Adds QuickLook preview for monster files. It shows how the monster will appear after being imported.

This commit is contained in:
2021-04-08 18:59:47 -07:00
committed by headhunter45
parent 346e3c1957
commit ebf01e2bb0
7 changed files with 467 additions and 20 deletions

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14750" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14710.3"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Preview View Controller-->
<scene sceneID="cwh-vc-ff4">
<objects>
<viewController id="M4Y-Lb-cyx" customClass="PreviewViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" simulatedAppContext="notificationCenter" id="S3S-Oj-5AN">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello World" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="GcN-lo-r42">
<rect key="frame" x="20" y="323.5" width="335" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" xcode11CocoaTouchSystemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="GcN-lo-r42" firstAttribute="centerY" secondItem="S3S-Oj-5AN" secondAttribute="centerY" id="44a-Fp-Kvy"/>
<constraint firstItem="GcN-lo-r42" firstAttribute="leading" secondItem="S3S-Oj-5AN" secondAttribute="leading" constant="20" symbolic="YES" id="6Vq-gs-PHe"/>
<constraint firstAttribute="trailing" secondItem="GcN-lo-r42" secondAttribute="trailing" constant="20" symbolic="YES" id="L8K-9R-egU"/>
</constraints>
<viewLayoutGuide key="safeArea" id="bzV-dz-m25"/>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="705" y="299"/>
</scene>
</scenes>
</document>

40
MonsterPreview/Info.plist Normal file
View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>MonsterPreview</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>QLSupportedContentTypes</key>
<array>
<string>com.majinnaibu.MonsterCards.Monster</string>
</array>
<key>QLSupportsSearchableItems</key>
<false/>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.quicklook.preview</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,43 @@
//
// PreviewViewController.swift
// MonsterPreview
//
// Created by Tom Hicks on 4/7/21.
//
import UIKit
import QuickLook
import SwiftUI
class PreviewViewController: UIViewController, QLPreviewingController {
func preparePreviewOfFile(at url: URL, completionHandler handler: @escaping (Error?) -> Void) {
let document = MonsterDocument(fileURL: url)
document.open(completionHandler: {[weak self](_) in
self?.presentMonsterViewController(for: document)
handler(nil)
})
}
func presentMonsterViewController(for document: MonsterDocument) {
let monsterViewModel = MonsterImportHelper.import5ESBMonster(document.monsterDTO ?? MonsterDTO())
let monsterViewController = UIHostingController(rootView: MonsterDetailView(viewModel: monsterViewModel))
monsterViewController.loadViewIfNeeded()
monsterViewController.view.layoutIfNeeded()
addChild(monsterViewController)
view.addSubview(monsterViewController.view)
monsterViewController.didMove(toParent: self)
if let monsterView = monsterViewController.view {
monsterView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
monsterView.leftAnchor.constraint(equalTo: view.leftAnchor),
monsterView.rightAnchor.constraint(equalTo: view.rightAnchor),
monsterView.topAnchor.constraint(equalTo: view.topAnchor),
monsterView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
}
}
}