Files
2022-04-27 15:12:29 +09:00

103 lines
3.0 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// ControlView.swift
// LifeGameApp
//
// Created by Yusuke Hosonuma on 2020/08/02.
//
import SwiftUI
import Combine
import Core
// FIXME: ObservableObject
private var cancellables: Set<AnyCancellable> = []
struct ControlView: View {
@EnvironmentObject var gameManager: GameManager
@EnvironmentObject var setting: SettingEnvironment
@EnvironmentObject var authentication: Authentication
@EnvironmentObject var network: NetworkMonitor
@EnvironmentObject var applicationRouter: ApplicationRouter
@State var presentedSheetSelect = false
// MARK: View
var body: some View {
VStack(spacing: 16) {
// Speed / Scale
HStack {
SpeedControlView(speed: $gameManager.speed, onEditingChanged: gameManager.speedChanged)
.padding(.trailing, 40)
ScaleChangeButton(scale: $gameManager.scale)
}
// Play/Stop, Next, Menus
HStack {
if gameManager.state == .stop {
playButton()
} else {
stopButton()
}
nextButton()
Spacer()
SheetButton(by: $presentedSheetSelect) {
Image(systemName: "list.bullet")
} content: {
PatternSelectSheetView(presented: $presentedSheetSelect)
.environmentObject(gameManager)
.environmentObject(authentication)
}
ActionMenuButton {
Button(action: {}) {
Image(systemName: "ellipsis")
}
}
}
.buttonStyle(ButtonStyleCircle())
}
.onReceive(applicationRouter.$didOpenPatteenURL.compactMap { $0 }, perform: didOpenPatternURL)
}
private func didOpenPatternURL(url: URL) {
gameManager.setPattern(from: url)
.sink {
self.presentedSheetSelect = false
}
.store(in: &cancellables)
}
private func playButton() -> some View {
Button(action: gameManager.play) {
Image(systemName: "play.fill")
}
.enabled(gameManager.state.canPlay)
}
private func stopButton() -> some View {
Button(action: gameManager.stop) {
Image(systemName: "stop.fill")
}
.buttonStyle(ButtonStyleCircle(color: .orange))
.enabled(gameManager.state.canStop)
}
private func nextButton() -> some View {
Button(action: gameManager.next) {
Image(systemName: "arrow.right.to.line.alt")
}
.enabled(gameManager.state.canNext)
}
}
//struct ControlView_Previews: PreviewProvider {
// static var previews: some View {
// ControlView(viewModel: MainGameViewModel())
// .previewLayout(.sizeThatFits)
// }
//}