Skip to content

Commit

Permalink
Added bottle settings to wine view
Browse files Browse the repository at this point in the history
Unified bottle settings backend
  • Loading branch information
vapidinfinity committed Feb 9, 2024
1 parent b0faa03 commit 5b3e704
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 147 deletions.
5 changes: 4 additions & 1 deletion Mythic/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -4634,6 +4634,9 @@
}
}
}
},
"Configure \"%@\"" : {

},
"Configure Mythic" : {

Expand Down Expand Up @@ -23756,4 +23759,4 @@
}
},
"version" : "1.0"
}
}
150 changes: 90 additions & 60 deletions Mythic/Views/BottleSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
struct BottleSettingsView: View {

@Binding var selectedBottle: String
var withPicker: Bool
@ObservedObject private var variables: VariableManager = .shared

@State private var bottleScope: Wine.BottleScope = .individual
Expand All @@ -34,74 +35,103 @@ struct BottleSettingsView: View {
}

var body: some View {
Form {
if Wine.allBottles?[selectedBottle] != nil {
Toggle("Performance HUD", isOn: Binding(
get: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
return Wine.individualBottleSettings![game.appName]!.metalHUD
case .global: */
return Wine.allBottles![selectedBottle]!.settings.metalHUD
// }
}, set: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
<#code#>
case .global: */
Wine.allBottles![selectedBottle]!.settings.metalHUD = $0
// }
}
))
.disabled(variables.getVariable("booting") == true)
if withPicker {
if variables.getVariable("booting") != true {
/* TODO: add support for different games having different configs under the same bottle
Picker("Bottle Scope", selection: $bottleScope) {
ForEach(type(of: bottleScope).allCases, id: \.self) {
Text($0.rawValue)
}
}
.pickerStyle(InlinePickerStyle())
*/

if !modifyingRetinaMode {
Toggle("Retina Mode", isOn: Binding( // FIXME: make retina mode work!!
get: { retinaMode },
set: { value in
Task(priority: .userInitiated) {
modifyingRetinaMode = true
do {
try await Wine.toggleRetinaMode(bottleURL: Wine.allBottles![selectedBottle]!.url, toggle: value)
retinaMode = value
Wine.allBottles![selectedBottle]!.settings.retinaMode = value
modifyingRetinaMode = false
} catch { }
}
}
))
.disabled(variables.getVariable("booting") == true)
.disabled(modifyingRetinaMode)
} else {
HStack {
Text("Retina Mode")
Spacer()
if retinaModeError == nil {
ProgressView()
.controlSize(.small)
} else {
Image(systemName: "exclamationmark.triangle.fill")
.controlSize(.small)
.help("Retina Mode cannot be modified: \(retinaModeError?.localizedDescription ?? "Unknown Error")")
}
Picker("Current Bottle", selection: $selectedBottle) { // also remember to make that the bottle it launches with
ForEach(Array((Wine.allBottles ?? .init()).keys), id: \.self) { name in
Text(name)
}
}

Toggle("Enhanced Sync (MSync)", isOn: Binding(
get: { return Wine.allBottles![selectedBottle]!.settings.msync },
set: { Wine.allBottles![selectedBottle]!.settings.msync = $0 }
))
.disabled(variables.getVariable("booting") == true)
.disabled(((Wine.allBottles?.contains { $0.key == "Default" }) == nil))
} else {
HStack {
Text("Current bottle:")
Spacer()
ProgressView()
.controlSize(.small)
}
}
}
.formStyle(.grouped)
.task(priority: .userInitiated) { await fetchRetinaStatus() }
.onChange(of: selectedBottle) {
Task(priority: .userInitiated) { await fetchRetinaStatus() }
if Wine.allBottles?[selectedBottle] != nil {
Toggle("Performance HUD", isOn: Binding(
get: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
return Wine.individualBottleSettings![game.appName]!.metalHUD
case .global: */
return Wine.allBottles![selectedBottle]!.settings.metalHUD
// }
}, set: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
<#code#>
case .global: */
Wine.allBottles![selectedBottle]!.settings.metalHUD = $0
// }
}
))
.disabled(variables.getVariable("booting") == true)

if !modifyingRetinaMode {
Toggle("Retina Mode", isOn: Binding( // FIXME: make retina mode work!!
get: { retinaMode },
set: { value in
Task(priority: .userInitiated) {
modifyingRetinaMode = true
do {
try await Wine.toggleRetinaMode(bottleURL: Wine.allBottles![selectedBottle]!.url, toggle: value)
retinaMode = value
Wine.allBottles![selectedBottle]!.settings.retinaMode = value
modifyingRetinaMode = false
} catch { }
}
}
))
.disabled(variables.getVariable("booting") == true)
.disabled(modifyingRetinaMode)
} else {
HStack {
Text("Retina Mode")
Spacer()
if retinaModeError == nil {
ProgressView()
.controlSize(.small)
} else {
Image(systemName: "exclamationmark.triangle.fill")
.controlSize(.small)
.help("Retina Mode cannot be modified: \(retinaModeError?.localizedDescription ?? "Unknown Error")")
}
}
}

Toggle("Enhanced Sync (MSync)", isOn: Binding(
get: { return Wine.allBottles![selectedBottle]!.settings.msync },
set: { Wine.allBottles![selectedBottle]!.settings.msync = $0 }
))
.disabled(variables.getVariable("booting") == true)
.task(priority: .userInitiated) { await fetchRetinaStatus() }
.onChange(of: selectedBottle) {
Task(priority: .userInitiated) { await fetchRetinaStatus() }
}
}
}
}

#Preview {
BottleSettingsView(selectedBottle: .constant("Default"))
Form {
BottleSettingsView(
selectedBottle: .constant("Default"),
withPicker: false
)
}
.formStyle(.grouped)
}
86 changes: 1 addition & 85 deletions Mythic/Views/GameList/Extensions/GameSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,91 +184,7 @@ extension GameListView {
}

Section("Wine", isExpanded: $isWineSectionExpanded) {
if let bottles = Wine.allBottles {
if variables.getVariable("booting") != true {
/* TODO: add support for different games having different configs under the same bottle
Picker("Bottle Scope", selection: $bottleScope) {
ForEach(type(of: bottleScope).allCases, id: \.self) {
Text($0.rawValue)
}
}
.pickerStyle(InlinePickerStyle())
*/

Picker("Current Bottle", selection: $selectedBottle) { // also remember to make that the bottle it launches with
ForEach(Array((Wine.allBottles ?? bottles).keys), id: \.self) { name in
Text(name)
}
}
.disabled(!bottles.contains { $0.key == "Default" })
} else {
HStack {
Text("Current bottle:")
Spacer()
ProgressView()
.controlSize(.small)
}
}
}

if Wine.allBottles?[selectedBottle] != nil {
Toggle("Performance HUD", isOn: Binding(
get: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
return Wine.individualBottleSettings![game.appName]!.metalHUD
case .global: */
return Wine.allBottles![selectedBottle]!.settings.metalHUD
// }
}, set: { /* TODO: add support for different games having different configs under the same bottle
switch bottleScope {
case .individual:
<#code#>
case .global: */
Wine.allBottles![selectedBottle]!.settings.metalHUD = $0
// }
}
))
.disabled(variables.getVariable("booting") == true)

if !modifyingRetinaMode {
Toggle("Retina Mode", isOn: Binding( // FIXME: make retina mode work!!
get: { retinaMode },
set: { value in
Task(priority: .userInitiated) {
modifyingRetinaMode = true
do {
try await Wine.toggleRetinaMode(bottleURL: Wine.allBottles![selectedBottle]!.url, toggle: value)
retinaMode = value
Wine.allBottles![selectedBottle]!.settings.retinaMode = value
modifyingRetinaMode = false
} catch { }
}
}
))
.disabled(variables.getVariable("booting") == true)
.disabled(modifyingRetinaMode)
} else {
HStack {
Text("Retina Mode")
Spacer()
if retinaModeError == nil {
ProgressView()
.controlSize(.small)
} else {
Image(systemName: "exclamationmark.triangle.fill")
.controlSize(.small)
.help("Retina Mode cannot be modified: \(retinaModeError?.localizedDescription ?? "Unknown Error")")
}
}
}

Toggle("Enhanced Sync (MSync)", isOn: Binding(
get: { return Wine.allBottles![selectedBottle]!.settings.msync },
set: { Wine.allBottles![selectedBottle]!.settings.msync = $0 }
))
.disabled(variables.getVariable("booting") == true)
}
BottleSettingsView(selectedBottle: $selectedBottle, withPicker: true)
}

Section("DXVK", isExpanded: $isDXVKSectionExpanded) {
Expand Down
19 changes: 18 additions & 1 deletion Mythic/Views/Navigation/Wine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct WineView: View {
@State private var isBottleCreationViewPresented = false
@State private var isBottleSettingsViewPresented = false

@State private var selectedBottleName: String = .init()

@State private var isDeletionAlertPresented = false

var body: some View {
Expand All @@ -37,6 +39,7 @@ struct WineView: View {

Spacer()
Button(action: {
selectedBottleName = name
isBottleSettingsViewPresented = true
}, label: {
Image(systemName: "gear")
Expand Down Expand Up @@ -75,7 +78,21 @@ struct WineView: View {
BottleCreationView(isPresented: $isBottleCreationViewPresented)
}
.sheet(isPresented: $isBottleSettingsViewPresented) {
// BottleSettingsView()
VStack {
Text("Configure \"\(selectedBottleName)\"")
.font(.title)

Form {
BottleSettingsView(selectedBottle: $selectedBottleName, withPicker: false)
}
.formStyle(.grouped)

Button("Close") {
isBottleSettingsViewPresented = false
}
}
.padding()
.fixedSize()
}
.alert(isPresented: $isDeletionAlertPresented) {
Alert(
Expand Down

0 comments on commit 5b3e704

Please sign in to comment.