Files
VCCPlusOSS/platforms/macos/App/SoftwareLibraryLaunchView.swift
T

142 lines
8.0 KiB
Swift
Raw 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.
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
#if !VCC_COMPANION_CLIENT
struct SoftwareLibraryLaunchPreviewView: View {
let preview: LibraryLaunchPreview
let confirm: () -> Void
let cancel: () -> Void
private var plan: SoftwareLibraryLaunchPlan { preview.plan }
private var setupName: String {
switch plan.profile {
case .diskBasic: return "Disk BASIC"
case .hardDriveBasic: return "Hard-drive BASIC"
case .romCartridge: return plan.cartridgeDevice == .orchestra90 ? "Orchestra-90" : "ROM Cartridge"
case .cocoSDC: return "CoCo SDC"
}
}
var body: some View {
VStack(alignment: .leading, spacing: 18) {
Label(plan.automaticallyStarts ? "Start Software" : plan.offersPlay ? "Play Software" : "Set Up Software", systemImage: "play.rectangle")
.font(.title2.weight(.semibold))
Text(plan.title).font(.title3.weight(.medium))
ScrollView {
VStack(alignment: .leading, spacing: 14) {
LabeledContent("Machine", value: "Color Computer 3")
LabeledContent("Processor", value: plan.use6309 ? "Hitachi 6309" : "Motorola 6809")
LabeledContent("Memory", value: plan.ramKiB >= 1024 ? "\(plan.ramKiB / 1024) MB" : "\(plan.ramKiB) KB")
LabeledContent("Setup", value: setupName)
LabeledContent("Video", value: DisplayOutput(rawValue: preview.prepared.profile.videoOutput)?.label ?? "Current signal")
if let previous = preview.prepared.previousSetup {
ForEach([1, 0], id: \.self) { port in
if previous.input[port].source != preview.prepared.profile.input[port].source {
Text((port == 0 ? "Right" : "Left") + " joystick input will change for this title’s controls.")
.font(.callout).foregroundStyle(.secondary)
}
}
}
Divider()
if let cart = plan.cartridgeURL {
LabeledContent(plan.cartridgeDevice == .orchestra90 ? "Orchestra-90" : "ROM cartridge", value: cart.lastPathComponent)
}
if let tape = plan.cassetteURL { Label(tape.lastPathComponent, systemImage: "recordingtape") }
ForEach(plan.floppyURLs.keys.sorted(), id: \.self) { drive in
LabeledContent("FD\(drive)", value: plan.floppyURLs[drive]!.lastPathComponent)
}
ForEach(plan.hardDiskURLs.keys.sorted(), id: \.self) { drive in
LabeledContent("HD\(drive)", value: plan.hardDiskURLs[drive]!.lastPathComponent)
}
if let folder = plan.sdcFolderURL { Label("SD card folder: " + folder.lastPathComponent, systemImage: "sdcard") }
if !plan.compatibilityNotes.isEmpty {
Text(plan.compatibilityNotes.joined(separator: "\n\n")).font(.callout).foregroundStyle(.secondary)
}
if !plan.automaticallyStarts {
Label("Manual loading", systemImage: "keyboard").font(.headline)
if plan.offersPlay {
Text(plan.commands.isEmpty
? "The CoCo will run with the selected media mounted. Load the program yourself; no loading commands will be typed automatically."
: "The CoCo will run with the selected media mounted and enter the commands below. Start the program yourself if those commands do not run it.")
.font(.callout)
}
Text(plan.manualInstructions).font(.callout).textSelection(.enabled)
}
if !plan.commands.isEmpty {
DisclosureGroup("Loading commands") {
Text(plan.commands.joined(separator: "\n")).font(.system(.callout, design: .monospaced)).textSelection(.enabled)
}
}
}.frame(maxWidth: .infinity, alignment: .leading)
}.frame(maxHeight: 330)
Text("Starting this setup restarts the CoCo and clears its current program. Unsaved media must be saved first.")
.font(.callout).fixedSize(horizontal: false, vertical: true)
if preview.prepared.previousSetup == nil {
Text("The current setup could not be captured for return. Your installed files will remain available.").font(.caption).foregroundStyle(.secondary)
}
HStack {
Button("Cancel", role: .cancel, action: cancel).keyboardShortcut(.cancelAction).accessibilityIdentifier("library-cancel-play")
Spacer()
Button(plan.automaticallyStarts ? "Start" : plan.offersPlay ? "Play" : "Set Up", action: confirm)
.buttonStyle(.borderedProminent).keyboardShortcut(.defaultAction).accessibilityIdentifier("library-confirm-play")
}
}.padding(24).frame(width: 490)
}
}
#endif
struct SoftwareLibraryMediaChoiceView: View {
let choice: LibraryMediaChoice
let choose: (String) -> Void
let cancel: () -> Void
@State private var selection: String?
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Label("Choose Starting Media", systemImage: "externaldrive").font(.title2.weight(.semibold))
Text("This collection has more than one possible starting file. Choose the one described by its loading instructions.")
.font(.callout)
List(selection: $selection) {
ForEach(choice.candidates, id: \.path) { candidate in
Text(candidate.path).tag(candidate.path)
}
}.frame(height: 240).accessibilityIdentifier("library-starting-media")
Text(choice.release.setup.instructions).font(.callout).foregroundStyle(.secondary).lineLimit(6)
HStack {
Button("Cancel", role: .cancel, action: cancel).keyboardShortcut(.cancelAction)
Spacer()
Button("Continue") { if let selection { choose(selection) } }
.disabled(selection == nil).keyboardShortcut(.defaultAction)
}
}.padding(24).frame(width: 520)
}
}
#if !VCC_COMPANION_CLIENT
struct SoftwareLibraryPersonalPresentation: ViewModifier {
@ObservedObject var model: SoftwareLibraryModel
func body(content: Content) -> some View {
content
.sheet(item: $model.personalEditor, onDismiss: { model.cancelPersonalEdit() }) { entry in
PersonalSoftwareEditor(entry: entry, unsupported: model.personalUnsupported, isImport: model.isPersonalImport,
saving: model.personalSaving, error: model.personalError, duplicateID: model.personalDuplicateID,
save: { model.savePersonal($0, coverPNG: $1, allowDuplicate: $2) }, openExisting: model.openExistingPersonal,
previewCover: model.personalCoverPreview,
cancel: model.cancelPersonalEdit)
}
.safeAreaInset(edge: .bottom) {
if model.personalInspecting {
HStack { ProgressView().controlSize(.small); Text("Preparing a private import preview…"); Spacer(); Button("Cancel", role: .cancel) { model.cancelPersonalInspection() } }.padding(10)
} else if model.personalEditor == nil, let error = model.personalError {
Label(error, systemImage: "exclamationmark.triangle").font(.callout).foregroundStyle(.orange)
.textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading).padding(10)
}
}
}
}
#else
import SwiftUI
struct SoftwareLibraryPersonalPresentation: ViewModifier {
let model: SoftwareLibraryModel
func body(content: Content) -> some View { content }
}
#endif