Skip to content

Manic EMU is an all-in-one retro game emulator for iOS. It packs powerful features while keeping a clean, sleek UI and delivering buttery-smooth gameplay.

Swift

Add a controller mapping feature for long-press fastforward

Daiuno1f442257bc01
diff --git a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
index 5288b4ff..f59c23f8 100644
--- a/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
+++ b/ManicEmu/ManicEmu/Resources/en.lproj/Localizable.strings
@@ -719,3 +719,5 @@ Press the controller button to complete mapping...";
"GlobalHardcoreAlert" = "Please enable Global RetroAchievements first.";
"ThreeDSNandImportToast" = "Please Dump the NAND from your 3DS device and compress it into an unencrypted nand.zip. This provides the missing system files required for 3DS emulation.";
"ThreeDSNandImportFailed" = "Incorrect nand.zip imported!";
+"HoldFastForward" = "Hold %@ FF";
+"HoldMaxFastForward" = "Hold Max FF";
diff --git a/ManicEmu/ManicEmu/Sources/Business/Common/Views/SettingItemCollectionViewCell.swift b/ManicEmu/ManicEmu/Sources/Business/Common/Views/SettingItemCollectionViewCell.swift
index 76c0e041..372e3b77 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Common/Views/SettingItemCollectionViewCell.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Common/Views/SettingItemCollectionViewCell.swift
@@ -171,4 +171,25 @@ class SettingItemCollectionViewCell: UICollectionViewCell {
longPressIcon.isHidden = true
}
}
+
+ func setDataForMappingOnly(item: SettingCellItem, enable: Bool = true) {
+ if item.title == R.string.localizable.gameSettingQuit() {
+ iconView.image = item.image.applySymbolConfig(color: Constants.Color.Red)
+ titleLabel.textColor = Constants.Color.Red
+ } else {
+ iconView.image = item.image
+ titleLabel.textColor = Constants.Color.LabelSecondary
+ }
+ titleLabel.text = item.title
+
+ editButton.isHidden = true
+ enableInteractive = true
+
+ editIcon.image = UIImage(symbol: .minus, font: Constants.Font.caption(size: .l, weight: .medium))
+ editButton.backgroundColor = Constants.Color.Red
+
+ disableCover.isHidden = enable
+
+ longPressIcon.isHidden = true
+ }
}
diff --git a/ManicEmu/ManicEmu/Sources/Business/Play/Models/GameSetting.swift b/ManicEmu/ManicEmu/Sources/Business/Play/Models/GameSetting.swift
index 567c7416..9c3413d3 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Play/Models/GameSetting.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Play/Models/GameSetting.swift
@@ -430,6 +430,58 @@ struct GameSetting: SettingCellItem {
}
}
+ enum MappingOnlyType: Int, CaseIterable, SettingCellItem {
+ case holdX2FastForward, holdX3FastForward, holdX4FastForward, holdMaxFastForward
+
+ var title: String {
+ switch self {
+ case .holdX2FastForward:
+ R.string.localizable.holdFastForward("2x")
+ case .holdX3FastForward:
+ R.string.localizable.holdFastForward("3x")
+ case .holdX4FastForward:
+ R.string.localizable.holdFastForward("4x")
+ case .holdMaxFastForward:
+ R.string.localizable.holdMaxFastForward()
+ }
+ }
+
+ var image: UIImage {
+ switch self {
+ case .holdX2FastForward, .holdX3FastForward, .holdX4FastForward, .holdMaxFastForward:
+ UIImage(symbol: .forward)
+ }
+ }
+
+ func enable(for gameType: GameType, defaultCore: Int) -> Bool {
+ if gameType == ._3ds,
+ (self == .holdX2FastForward || self == .holdX3FastForward || self == .holdX4FastForward || self == .holdMaxFastForward) {
+ return false
+ }
+ return true
+ }
+
+ var enableLongPress: Bool {
+ switch self {
+ case .holdX2FastForward, .holdX3FastForward, .holdX4FastForward, .holdMaxFastForward:
+ return false
+ }
+ }
+
+ var inputKey: String {
+ switch self {
+ case .holdX2FastForward:
+ "fastForward2x"
+ case .holdX3FastForward:
+ "fastForward3x"
+ case .holdX4FastForward:
+ "fastForward4x"
+ case .holdMaxFastForward:
+ "fastForward"
+ }
+ }
+ }
+
enum ItemType: Int, CaseIterable {
//位置很重要 新增内容一定要接到最后面
case saveState, quickLoadState, volume, fastForward, stateList, cheatCode, skins, filter, screenShot, haptic, airplay, controllerSetting, orientation, functionSort, reload, quit, swapScreen, resolution, consoleHome, amiibo, toggleFullscreen, simBlowing, palette, swapDisk, retro, airPlayScaling, airPlayLayout, toggleAnalog
@@ -448,6 +500,7 @@ struct GameSetting: SettingCellItem {
var currentDiskIndex: UInt = 0
var airPlayScaling: AirPlayScaling = .coreProvided
var airPlayLayout: AirPlayLayout = .sideBySide
+ var mappingOnlyType: MappingOnlyType? = nil
var image: UIImage {
switch type {
@@ -580,6 +633,10 @@ struct GameSetting: SettingCellItem {
}
func enable(for gameType: GameType, defaultCore: Int) -> Bool {
+ if let mappingOnlyType {
+ return mappingOnlyType.enable(for: gameType, defaultCore: defaultCore)
+ }
+
if type == .airPlayLayout {
return gameType == .ds
}
@@ -650,67 +707,76 @@ struct GameSetting: SettingCellItem {
}
var inputKey: String {
+ if let mappingOnlyType {
+ return mappingOnlyType.inputKey
+ }
+
switch self.type {
case .saveState:
- "quickSave"
+ return "quickSave"
case .quickLoadState:
- "quickLoad"
+ return "quickLoad"
case .volume:
- "volume"
+ return "volume"
case .fastForward:
- "toggleFastForward"
+ return "toggleFastForward"
case .stateList:
- "saveStates"
+ return "saveStates"
case .cheatCode:
- "cheatCodes"
+ return "cheatCodes"
case .skins:
- "skins"
+ return "skins"
case .filter:
- "filters"
+ return "filters"
case .screenShot:
- "screenshot"
+ return "screenshot"
case .haptic:
- "haptics"
+ return "haptics"
case .airplay:
- "airplay"
+ return "airplay"
case .controllerSetting:
- "controllers"
+ return "controllers"
case .orientation:
- "orientation"
+ return "orientation"
case .functionSort:
- "functionLayout"
+ return "functionLayout"
case .reload:
- "restart"
+ return "restart"
case .quit:
- "quit"
+ return "quit"
case .swapScreen:
- "reverseScreens"
+ return "reverseScreens"
case .resolution:
- "resolution"
+ return "resolution"
case .consoleHome:
- "homeMenu"
+ return "homeMenu"
case .amiibo:
- "amiibo"
+ return "amiibo"
case .toggleFullscreen:
- "toggleControlls"
+ return "toggleControlls"
case .simBlowing:
- "blowing"
+ return "blowing"
case .palette:
- "palette"
+ return "palette"
case .swapDisk:
- "swapDisk"
+ return "swapDisk"
case .retro:
- "retroAchievements"
+ return "retroAchievements"
case .airPlayScaling:
- "airPlayScaling"
+ return "airPlayScaling"
case .airPlayLayout:
- "airPlayLayout"
+ return "airPlayLayout"
case .toggleAnalog:
- "toggleAnalog"
+ return "toggleAnalog"
}
}
static func isValidInputKey(_ inputKey: String) -> Bool {
- return ["quickSave", "quickLoad", "volume", "toggleFastForward", "saveStates", "cheatCodes", "skins", "filters", "screenshot", "haptics", "airplay", "controllers", "orientation", "functionLayout", "restart", "quit", "reverseScreens", "resolution", "homeMenu", "amiibo", "toggleControlls", "blowing", "palette", "swapDisk", "retroAchievements", "airPlayScaling", "airPlayLayout", "toggleAnalog"].contains([inputKey])
+ if GameSetting.ItemType.allCases.contains(where: { GameSetting(type: $0).inputKey == inputKey }) {
+ return true
+ } else if MappingOnlyType.allCases.contains(where: { $0.inputKey == inputKey }) {
+ return true
+ }
+ return false
}
}
diff --git a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift
index be881025..c7f096f5 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift
@@ -889,12 +889,26 @@ class PlayViewController: GameViewController {
handleMenuGameSetting(GameSetting(type: .saveState), nil)
} else if input.stringValue == "quickLoad" {
handleMenuGameSetting(GameSetting(type: .quickLoadState), nil)
- } else if input.stringValue == "fastForward" {
- if PurchaseManager.isMember {
+ } else if input.stringValue == "fastForward" ||
+ input.stringValue == "fastForward2x" ||
+ input.stringValue == "fastForward3x" ||
+ input.stringValue == "fastForward4x" {
+ if !PurchaseManager.isMember {
manicEmuCore?.setRate(speed: .two)
} else {
if manicGame.speed.rawValue < GameSetting.FastForwardSpeed.five.rawValue {
- manicEmuCore?.setRate(speed: .five)
+ let speed: GameSetting.FastForwardSpeed
+ if input.stringValue == "fastForward2x" {
+ speed = .two
+ } else if input.stringValue == "fastForward3x" {
+ speed = .three
+ } else if input.stringValue == "fastForward4x" {
+ speed = .four
+ } else {
+ speed = .five
+ }
+ Log.debug("长按速度: \(speed.rawValue)x")
+ manicEmuCore?.setRate(speed: speed)
}
}
} else if input.stringValue == "toggleFastForward" {
@@ -959,8 +973,12 @@ class PlayViewController: GameViewController {
override func gameController(_ gameController: any GameController, didDeactivate input: any Input) {
super.gameController(gameController, didDeactivate: input)
- if input.stringValue == "fastForward" {
+ if input.stringValue == "fastForward" ||
+ input.stringValue == "fastForward2x" ||
+ input.stringValue == "fastForward3x" ||
+ input.stringValue == "fastForward4x" {
manicEmuCore?.setRate(speed: manicGame.speed)
+ Log.debug("长按结束,恢复原速度")
}
}
diff --git a/ManicEmu/ManicEmu/Sources/Business/Play/Views/GameSettingView.swift b/ManicEmu/ManicEmu/Sources/Business/Play/Views/GameSettingView.swift
index 1f15fb4e..ad58f61b 100644
--- a/ManicEmu/ManicEmu/Sources/Business/Play/Views/GameSettingView.swift
+++ b/ManicEmu/ManicEmu/Sources/Business/Play/Views/GameSettingView.swift
@@ -236,6 +236,13 @@ class GameSettingView: BaseView {
}
return nil
}
+
+ if isMappingMode {
+ gameSettings.append(contentsOf: GameSetting.MappingOnlyType.allCases.map({
+ return GameSetting(type: .quit, mappingOnlyType: $0)
+ }))
+ }
+
collectionView.reloadData()
}
@@ -355,7 +362,12 @@ extension GameSettingView: UICollectionViewDataSource {
}
}
- cell.setData(item: item, editable: isEditingMode, isPlus: indexPath.section != 0, enable: item.enable(for: game.gameType, defaultCore: game.defaultCore), mappingMode: isMappingMode, specialTitle: specialTitle)
+ if isMappingMode, let mappingItem = item.mappingOnlyType {
+ cell.setDataForMappingOnly(item: mappingItem)
+ } else {
+ cell.setData(item: item, editable: isEditingMode, isPlus: indexPath.section != 0, enable: item.enable(for: game.gameType, defaultCore: game.defaultCore), mappingMode: isMappingMode, specialTitle: specialTitle)
+ }
+
if isEditingMode {
cell.editButton.addTapGesture { [weak self] gesture in
guard let self = self else { return }