Adds ability to adjust translucent controller skin opacity
This commit is contained in:
parent
754c327cc1
commit
e74725420a
@ -19,6 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
|
||||
{
|
||||
Settings.registerDefaults()
|
||||
|
||||
Delta.register(SNES.core)
|
||||
Delta.register(GBA.core)
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ class GameViewController: DeltaCore.GameViewController
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.updateControllers), name: .externalControllerDidConnect, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.updateControllers), name: .externalControllerDidDisconnect, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.didEnterBackground(with:)), name: .UIApplicationDidEnterBackground, object: UIApplication.shared)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.preferredControllerSkinDidUpdate(with:)), name: .preferredControllerSkinDidUpdate, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(GameViewController.settingsDidChange(with:)), name: .settingsDidChange, object: nil)
|
||||
}
|
||||
|
||||
deinit
|
||||
@ -197,15 +197,8 @@ extension GameViewController
|
||||
{
|
||||
super.viewWillTransition(to: size, with: coordinator)
|
||||
|
||||
guard let game = self.game else { return }
|
||||
|
||||
var traits = DeltaCore.ControllerSkin.Traits.defaults(for: self.view)
|
||||
traits.orientation = (size.width > size.height) ? .landscape : .portrait
|
||||
|
||||
let controllerSkin = Settings.preferredControllerSkin(for: game.type, traits: traits)
|
||||
|
||||
coordinator.animate(alongsideTransition: { (context) in
|
||||
self.controllerView.controllerSkin = controllerSkin
|
||||
self.updateControllerSkin()
|
||||
}, completion: nil)
|
||||
}
|
||||
|
||||
@ -389,6 +382,15 @@ private extension GameViewController
|
||||
|
||||
let controllerSkin = Settings.preferredControllerSkin(for: game.type, traits: traits)
|
||||
self.controllerView.controllerSkin = controllerSkin
|
||||
|
||||
if controllerSkin?.isTranslucent(for: traits) ?? false
|
||||
{
|
||||
self.controllerView.alpha = Settings.translucentControllerSkinOpacity
|
||||
}
|
||||
else
|
||||
{
|
||||
self.controllerView.alpha = 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -762,17 +764,35 @@ private extension GameViewController
|
||||
}
|
||||
}
|
||||
|
||||
@objc func preferredControllerSkinDidUpdate(with notification: Notification)
|
||||
@objc func settingsDidChange(with notification: Notification)
|
||||
{
|
||||
guard
|
||||
let gameType = notification.userInfo?[Settings.NotificationUserInfoKey.gameType.rawValue] as? GameType,
|
||||
let traits = notification.userInfo?[Settings.NotificationUserInfoKey.traits.rawValue] as? DeltaCore.ControllerSkin.Traits
|
||||
else { return }
|
||||
guard let settingsName = notification.userInfo?[Settings.NotificationUserInfoKey.name] as? Settings.Name else { return }
|
||||
|
||||
let currentTraits = DeltaCore.ControllerSkin.Traits.defaults(for: self.view)
|
||||
if gameType == self.game?.type && traits == currentTraits
|
||||
switch settingsName
|
||||
{
|
||||
self.updateControllerSkin()
|
||||
case .preferredControllerSkin:
|
||||
guard
|
||||
let gameType = notification.userInfo?[Settings.NotificationUserInfoKey.gameType] as? GameType,
|
||||
let traits = notification.userInfo?[Settings.NotificationUserInfoKey.traits] as? DeltaCore.ControllerSkin.Traits
|
||||
else { return }
|
||||
|
||||
let currentTraits = DeltaCore.ControllerSkin.Traits.defaults(for: self.view)
|
||||
if gameType == self.game?.type && traits == currentTraits
|
||||
{
|
||||
self.updateControllerSkin()
|
||||
}
|
||||
|
||||
case .translucentControllerSkinOpacity:
|
||||
if let traits = self.controllerView.controllerSkinTraits
|
||||
{
|
||||
if self.controllerView.controllerSkin?.isTranslucent(for: traits) ?? false
|
||||
{
|
||||
self.controllerView.alpha = Settings.translucentControllerSkinOpacity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="ssH-mM-uG6">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11760" systemVersion="16B2657" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="ssH-mM-uG6">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11755"/>
|
||||
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
@ -21,7 +22,7 @@
|
||||
<tableViewSection headerTitle="Inputs" id="c6K-sJ-0vW">
|
||||
<cells>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="tls-Hv-Rx2" detailTextLabel="vJP-Ie-a9H" style="IBUITableViewCellStyleValue1" id="jvV-ZB-Rq1">
|
||||
<rect key="frame" x="0.0" y="55.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="56" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="jvV-ZB-Rq1" id="AVi-6C-eIS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -45,7 +46,7 @@
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="e3u-x9-IEC" detailTextLabel="2OP-A1-VYo" style="IBUITableViewCellStyleValue1" id="1Fv-H5-0oH">
|
||||
<rect key="frame" x="0.0" y="99.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="100" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="1Fv-H5-0oH" id="kFJ-zK-MLZ">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -69,7 +70,7 @@
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="Cdn-11-xZe" detailTextLabel="wWc-NY-Bsd" style="IBUITableViewCellStyleValue1" id="EcC-Be-jV5">
|
||||
<rect key="frame" x="0.0" y="143.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="144" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EcC-Be-jV5" id="9ZS-um-scR">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -93,7 +94,7 @@
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="Hls-3b-EaS" detailTextLabel="hNf-uc-PLR" style="IBUITableViewCellStyleValue1" id="hO9-Ov-vsA">
|
||||
<rect key="frame" x="0.0" y="187.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="188" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hO9-Ov-vsA" id="MRi-re-XI7">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -121,7 +122,7 @@
|
||||
<tableViewSection headerTitle="Controller Skins" id="Nch-k1-6pR">
|
||||
<cells>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="mBC-YU-BVK" style="IBUITableViewCellStyleDefault" id="ICf-ug-NwS">
|
||||
<rect key="frame" x="0.0" y="287.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="289" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ICf-ug-NwS" id="7se-sE-x9e">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -138,7 +139,7 @@
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="MFD-lC-Vfk" style="IBUITableViewCellStyleDefault" id="4Sh-Mb-vqu">
|
||||
<rect key="frame" x="0.0" y="331.5" width="375" height="44"/>
|
||||
<rect key="frame" x="0.0" y="333" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="4Sh-Mb-vqu" id="cJG-Gr-n6q">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
@ -156,6 +157,46 @@
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
<tableViewSection headerTitle="Controller Opacity" footerTitle="Determines how translucent the controller appears, if supported by the controller skin." id="SwK-m9-8gt">
|
||||
<cells>
|
||||
<tableViewCell contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="Xxk-vo-eu4">
|
||||
<rect key="frame" x="0.0" y="441" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" tableViewCell="Xxk-vo-eu4" id="vxt-Ex-b4b">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="whi-If-wFf">
|
||||
<rect key="frame" x="74" y="7" width="288" height="31"/>
|
||||
<connections>
|
||||
<action selector="changeControllerOpacityWith:" destination="eHi-aO-uGS" eventType="valueChanged" id="Zci-tN-4uU"/>
|
||||
<action selector="didFinishChangingControllerOpacityWith:" destination="eHi-aO-uGS" eventType="touchUpInside" id="T9j-dn-oV6"/>
|
||||
<action selector="didFinishChangingControllerOpacityWith:" destination="eHi-aO-uGS" eventType="touchCancel" id="YDh-63-VML"/>
|
||||
<action selector="didFinishChangingControllerOpacityWith:" destination="eHi-aO-uGS" eventType="touchUpOutside" id="xBn-FJ-5S0"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="50%" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zaz-yD-CYG">
|
||||
<rect key="frame" x="15" y="11" width="46" height="21"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="21" id="ACD-qY-k0J"/>
|
||||
<constraint firstAttribute="width" constant="46" id="ZVd-ie-qRm"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="whi-If-wFf" secondAttribute="trailing" id="2Gm-cE-goJ"/>
|
||||
<constraint firstItem="zaz-yD-CYG" firstAttribute="top" secondItem="vxt-Ex-b4b" secondAttribute="top" constant="11" id="Wy7-Fc-ddC"/>
|
||||
<constraint firstAttribute="centerY" secondItem="whi-If-wFf" secondAttribute="centerY" id="dgf-fj-2LW"/>
|
||||
<constraint firstItem="zaz-yD-CYG" firstAttribute="leading" secondItem="vxt-Ex-b4b" secondAttribute="leadingMargin" id="jYr-wU-Nbl"/>
|
||||
<constraint firstItem="whi-If-wFf" firstAttribute="leading" secondItem="zaz-yD-CYG" secondAttribute="trailing" constant="15" id="oEh-Az-8FJ"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
</sections>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="eHi-aO-uGS" id="rsh-0y-8Ex"/>
|
||||
@ -170,6 +211,8 @@
|
||||
</barButtonItem>
|
||||
</navigationItem>
|
||||
<connections>
|
||||
<outlet property="controllerOpacityLabel" destination="zaz-yD-CYG" id="eUW-u9-xxx"/>
|
||||
<outlet property="controllerOpacitySlider" destination="whi-If-wFf" id="6Cx-HY-xLG"/>
|
||||
<segue destination="uBz-mm-mXr" kind="show" identifier="controllersSegue" id="MLY-hF-UB8"/>
|
||||
<segue destination="56e-ul-z6v" kind="show" identifier="controllerSkinsSegue" id="GNM-Gt-YFf"/>
|
||||
</connections>
|
||||
|
||||
@ -16,22 +16,49 @@ import Roxas
|
||||
|
||||
extension Notification.Name
|
||||
{
|
||||
static let preferredControllerSkinDidUpdate = Notification.Name("PreferredControllerSkinDidUpdateNotification")
|
||||
static let settingsDidChange = Notification.Name("SettingsDidChangeNotification")
|
||||
}
|
||||
|
||||
extension Settings
|
||||
{
|
||||
enum NotificationUserInfoKey: String
|
||||
{
|
||||
case name
|
||||
|
||||
case gameType
|
||||
case traits
|
||||
}
|
||||
|
||||
enum Name: String
|
||||
{
|
||||
case localControllerPlayerIndex
|
||||
case translucentControllerSkinOpacity
|
||||
case preferredControllerSkin
|
||||
}
|
||||
}
|
||||
|
||||
struct Settings
|
||||
{
|
||||
/// Controllers
|
||||
static var localControllerPlayerIndex: Int? = 0
|
||||
static var localControllerPlayerIndex: Int? = 0 {
|
||||
didSet {
|
||||
NotificationCenter.default.post(name: .settingsDidChange, object: nil, userInfo: [NotificationUserInfoKey.name: Name.localControllerPlayerIndex])
|
||||
}
|
||||
}
|
||||
|
||||
static var translucentControllerSkinOpacity: CGFloat {
|
||||
set {
|
||||
UserDefaults.standard.translucentControllerSkinOpacity = newValue
|
||||
NotificationCenter.default.post(name: .settingsDidChange, object: nil, userInfo: [NotificationUserInfoKey.name: Name.translucentControllerSkinOpacity])
|
||||
}
|
||||
get { return UserDefaults.standard.translucentControllerSkinOpacity }
|
||||
}
|
||||
|
||||
static func registerDefaults()
|
||||
{
|
||||
let defaults = [#keyPath(UserDefaults.translucentControllerSkinOpacity): 1.0]
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
|
||||
static func preferredControllerSkin(for gameType: GameType, traits: DeltaCore.ControllerSkin.Traits) -> ControllerSkin?
|
||||
{
|
||||
@ -78,7 +105,7 @@ struct Settings
|
||||
guard let userDefaultKey = self.preferredControllerSkinKey(for: gameType, traits: traits) else { return }
|
||||
UserDefaults.standard.set(controllerSkin.identifier, forKey: userDefaultKey)
|
||||
|
||||
NotificationCenter.default.post(name: .preferredControllerSkinDidUpdate, object: controllerSkin, userInfo: [NotificationUserInfoKey.gameType.rawValue: gameType, NotificationUserInfoKey.traits.rawValue: traits])
|
||||
NotificationCenter.default.post(name: .settingsDidChange, object: controllerSkin, userInfo: [NotificationUserInfoKey.name: Name.preferredControllerSkin, NotificationUserInfoKey.gameType: gameType, NotificationUserInfoKey.traits: traits])
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,3 +142,8 @@ private extension Settings
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
private extension UserDefaults
|
||||
{
|
||||
@NSManaged var translucentControllerSkinOpacity: CGFloat
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ extension SettingsViewController
|
||||
{
|
||||
case controllers
|
||||
case controllerSkins
|
||||
case controllerOpacity
|
||||
}
|
||||
|
||||
fileprivate enum Segue: String
|
||||
@ -26,6 +27,9 @@ extension SettingsViewController
|
||||
|
||||
class SettingsViewController: UITableViewController
|
||||
{
|
||||
@IBOutlet fileprivate var controllerOpacityLabel: UILabel!
|
||||
@IBOutlet fileprivate var controllerOpacitySlider: UISlider!
|
||||
|
||||
required init?(coder aDecoder: NSCoder)
|
||||
{
|
||||
super.init(coder: aDecoder)
|
||||
@ -37,6 +41,9 @@ class SettingsViewController: UITableViewController
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
self.controllerOpacitySlider.value = Float(Settings.translucentControllerSkinOpacity)
|
||||
self.updateControllerOpacityLabel()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool)
|
||||
@ -82,6 +89,15 @@ class SettingsViewController: UITableViewController
|
||||
}
|
||||
}
|
||||
|
||||
private extension SettingsViewController
|
||||
{
|
||||
func updateControllerOpacityLabel()
|
||||
{
|
||||
let percentage = String(format: "%.f", Settings.translucentControllerSkinOpacity * 100) + "%"
|
||||
self.controllerOpacityLabel.text = percentage
|
||||
}
|
||||
}
|
||||
|
||||
private extension SettingsViewController
|
||||
{
|
||||
@IBAction func unwindFromControllersSettingsViewController(_ segue: UIStoryboardSegue)
|
||||
@ -94,6 +110,22 @@ private extension SettingsViewController
|
||||
}
|
||||
}
|
||||
|
||||
private extension SettingsViewController
|
||||
{
|
||||
@IBAction func changeControllerOpacity(with sender: UISlider)
|
||||
{
|
||||
let roundedValue = (sender.value / 0.05).rounded() * 0.05
|
||||
Settings.translucentControllerSkinOpacity = CGFloat(roundedValue)
|
||||
|
||||
self.updateControllerOpacityLabel()
|
||||
}
|
||||
|
||||
@IBAction func didFinishChangingControllerOpacity(with sender: UISlider)
|
||||
{
|
||||
sender.value = Float(Settings.translucentControllerSkinOpacity)
|
||||
}
|
||||
}
|
||||
|
||||
private extension SettingsViewController
|
||||
{
|
||||
dynamic func externalControllerDidConnect(_ notification: Notification)
|
||||
@ -142,6 +174,7 @@ extension SettingsViewController
|
||||
{
|
||||
case Section.controllers: self.performSegue(withIdentifier: Segue.controllers.rawValue, sender: cell)
|
||||
case Section.controllerSkins: self.performSegue(withIdentifier: Segue.controllerSkins.rawValue, sender: cell)
|
||||
case Section.controllerOpacity: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user