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
Fix the issue where in-game alerts don't follow the menu insets
Daiuno85b94ba2fd09
diff --git a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swiftindex 14db40b3..be881025 100644--- a/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift+++ b/ManicEmu/ManicEmu/Sources/Business/Play/VIewControllers/PlayViewController.swift@@ -745,10 +745,14 @@ class PlayViewController: GameViewController {muteSwitchMonitor.stopMonitoring()}+ //通知游戏列表更新if let gameSortType = GameSortType(rawValue: Theme.defalut.getExtraInt(key: ExtraKey.gameSortType.rawValue) ?? 0),(gameSortType == .latestPlayed || gameSortType == .playTime) {NotificationCenter.default.post(name: Constants.NotificationName.GameSortChange, object: nil)}++ //取消Alert的MenuInset+ UIView.alertBottomInset = nil}/// 进入默认显示的方向@@ -812,7 +816,7 @@ class PlayViewController: GameViewController {}GameSettingView.show(game: manicGame,gameViewRect: gameView.frame,- menuInsets: getMenuInset(),+ menuInsets: getMenuInsets(),didSelectItem: { [weak self] item, sheet in//点击菜单选项guard let self = self else { return true }@@ -1155,6 +1159,7 @@ extension PlayViewController {}switch item.type {case .saveState:+ //MARK: handleMenuGameSetting.saveStateguard !isWFCConnect else {UIView.makeToast(message: R.string.localizable.notAllowOnlineGame())return true@@ -1186,6 +1191,7 @@ extension PlayViewController {saveStateForLibretro(type: .manualSaveState)}case .quickLoadState:+ //MARK: handleMenuGameSetting.quickLoadStateguard !isWFCConnect else {UIView.makeToast(message: R.string.localizable.notAllowOnlineGame())return true@@ -1201,6 +1207,7 @@ extension PlayViewController {quickLoadStateForLibretro(item.loadState)}case .volume:+ //MARK: handleMenuGameSetting.volume//声音设置//恢复游戏的时候会直接使用新配置Game.change { realm in@@ -1213,6 +1220,7 @@ extension PlayViewController {}UIView.makeToast(message: item.volumeOn ? R.string.localizable.volumeOn(): R.string.localizable.volumeOff(), identifier: "gameVolume")case .fastForward:+ //MARK: handleMenuGameSetting.fastForwardguard !isWFCConnect else {UIView.makeToast(message: R.string.localizable.notAllowOnlineGame())return true@@ -1259,6 +1267,7 @@ extension PlayViewController {}return falsecase .stateList:+ //MARK: handleMenuGameSetting.stateListguard !isWFCConnect else {UIView.makeToast(message: R.string.localizable.notAllowOnlineGame())return true@@ -1270,7 +1279,7 @@ extension PlayViewController {if menuSheet == nil {pauseEmulation()}- GameInfoView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInset(), selection: { [weak self, weak menuSheet] saveState in+ GameInfoView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInsets(), selection: { [weak self, weak menuSheet] saveState inguard let self = self else { return }func loadSave() {if self.manicGame.gameType == ._3ds {@@ -1301,6 +1310,7 @@ extension PlayViewController {})return falsecase .cheatCode:+ //MARK: handleMenuGameSetting.cheatCodeguard !isWFCConnect else {UIView.makeToast(message: R.string.localizable.notAllowOnlineGame())return true@@ -1315,7 +1325,7 @@ extension PlayViewController {if menuSheet == nil {pauseEmulation()}- CheatCodeListView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInset(), hideCompletion: { [weak self] in+ CheatCodeListView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInsets(), hideCompletion: { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()}@@ -1323,22 +1333,24 @@ extension PlayViewController {}return falsecase .skins:+ //MARK: handleMenuGameSetting.skinsif menuSheet == nil {pauseEmulation()}- SkinSettingsView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInset(), hideCompletion: { [weak self] in+ SkinSettingsView.show(game: manicGame, gameViewRect: gameView.frame, menuInsets: getMenuInsets(), hideCompletion: { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()}})return falsecase .filter:+ //MARK: handleMenuGameSetting.filterguard manicGame.gameType != ._3ds else { return true }if menuSheet == nil {pauseEmulation()}if manicGame.gameType.isLibretroType {- FilterSelectionView.show(game: self.manicGame, snapshot: nil, gameViewRect: self.gameView.frame, menuInsets: getMenuInset(), hideCompletion: { [weak self] in+ FilterSelectionView.show(game: self.manicGame, snapshot: nil, gameViewRect: self.gameView.frame, menuInsets: getMenuInsets(), hideCompletion: { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()}@@ -1346,6 +1358,7 @@ extension PlayViewController {}return falsecase .screenShot:+ //MARK: handleMenuGameSetting.screenShot//截屏if manicGame.gameType == ._3ds {if let images = self.snapShotFor3DS() {@@ -1386,6 +1399,7 @@ extension PlayViewController {return false}case .haptic:+ //MARK: handleMenuGameSetting.hapticswitch item.hapticType {case .off:break@@ -1408,10 +1422,11 @@ extension PlayViewController {UIView.makeToast(message: item.hapticType.title, identifier: "hapticType")return falsecase .airplay:+ //MARK: handleMenuGameSetting.airplayif menuSheet == nil {pauseEmulation()}- let vc = WebViewController(url: Constants.URLs.AirPlayUsageGuide, isShow: true, bottomInset: getMenuInset()?.bottom ?? nil)+ let vc = WebViewController(url: Constants.URLs.AirPlayUsageGuide, isShow: true, bottomInset: getMenuInsets()?.bottom ?? nil)vc.didClose = { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()@@ -1420,16 +1435,18 @@ extension PlayViewController {topViewController()?.present(vc, animated: true)return falsecase .controllerSetting:+ //MARK: handleMenuGameSetting.controllerSettingif menuSheet == nil {pauseEmulation()}- ControllersSettingView.show(gameType: manicGame.gameType, gameViewRect: gameView.frame, menuInsets: getMenuInset(), hideCompletion: { [weak self] in+ ControllersSettingView.show(gameType: manicGame.gameType, gameViewRect: gameView.frame, menuInsets: getMenuInsets(), hideCompletion: { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()}})return falsecase .orientation:+ //MARK: handleMenuGameSetting.orientationif manicGame.orientation != item.orientation {Game.change { realm inmanicGame.orientation = item.orientation@@ -1443,16 +1460,18 @@ extension PlayViewController {}return truecase .functionSort:+ //MARK: handleMenuGameSetting.functionSortif menuSheet == nil {pauseEmulation()}- GameSettingView.show(game: manicGame, gameViewRect: gameView.frame, isEditingMode: true, menuInsets: getMenuInset(), hideCompletion: { [weak self] in+ GameSettingView.show(game: manicGame, gameViewRect: gameView.frame, isEditingMode: true, menuInsets: getMenuInsets(), hideCompletion: { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()}})return falsecase .reload:+ //MARK: handleMenuGameSetting.reloadif manicGame.gameType == ._3ds {threeDSCore?.reload()} else if manicGame.gameType.isLibretroType {@@ -1460,6 +1479,7 @@ extension PlayViewController {updateFilter()}case .quit:+ //MARK: handleMenuGameSetting.quitif manicGame.gameType == ._3ds {threeDSCore?.stop()DispatchQueue.main.asyncAfter(delay: 0.5) {@@ -1473,6 +1493,7 @@ extension PlayViewController {}}case .resolution:+ //MARK: handleMenuGameSetting.resolutionguard manicGame.gameType == ._3ds || manicGame.gameType == .psp || manicGame.gameType == .n64 || manicGame.gameType == .ps1 || manicGame.gameType == .dc else { return true }Log.debug("设置分辨率")if manicGame.resolution != item.resolution {@@ -1502,6 +1523,7 @@ extension PlayViewController {UIView.makeToast(message: message, identifier: "resolution")return manicGame.gameType == .psp //psp需要隐藏菜单(恢复游戏) 才能生效case .swapScreen:+ //MARK: handleMenuGameSetting.swapScreenif enableSwapScreen() {Game.change { realm inmanicGame.swapScreen = !manicGame.swapScreen@@ -1509,6 +1531,7 @@ extension PlayViewController {updateSkin()}case .consoleHome:+ //MARK: handleMenuGameSetting.consoleHome//回到主页if manicGame.gameType == ._3ds, let threeDSCore {if manicGame.is3DSHomeMenuGame {@@ -1520,6 +1543,7 @@ extension PlayViewController {}}case .amiibo:+ //MARK: handleMenuGameSetting.amiibo//加载amiiboif manicGame.gameType == ._3ds, let threeDSCore {if threeDSCore.isAmiiboSearching() {@@ -1546,10 +1570,12 @@ extension PlayViewController {}}case .toggleFullscreen:+ //MARK: handleMenuGameSetting.toggleFullscreenmanicGame.forceFullSkin = item.isFullScreenupdateSkin()case .simBlowing:+ //MARK: handleMenuGameSetting.simBlowingguard manicGame.gameType == ._3ds else { return false }threeDSCore?.setSimBlowing(start: true)DispatchQueue.main.asyncAfter(delay: 5) { [weak self] in@@ -1557,6 +1583,7 @@ extension PlayViewController {}case .palette:+ //MARK: handleMenuGameSetting.paletteguard (manicGame.gameType == .gb || manicGame.gameType == .vb || manicGame.gameType == .pm) else { return false }if manicGame.pallete != item.palette {Game.change { realm in@@ -1586,6 +1613,7 @@ extension PlayViewController {}}case .swapDisk:+ //MARK: handleMenuGameSetting.swapDiskguard manicGame.gameType == .mcd || manicGame.gameType == .ss || manicGame.gameType == .ps1 || manicGame.gameType == .dc else { return false }if manicGame.supportSwapDisc {LibretroCore.sharedInstance().setDiskIndex(UInt32(item.currentDiskIndex), delay: manicGame.gameType == .ps1 ? true : false)@@ -1595,11 +1623,12 @@ extension PlayViewController {}return falsecase .retro:+ //MARK: handleMenuGameSetting.retroif menuSheet == nil {pauseEmulation()}func openRetroAchievementsList() {- let vc = RetroAchievementsListViewController(game: manicGame, bottomInset: getMenuInset()?.bottom ?? nil)+ let vc = RetroAchievementsListViewController(game: manicGame, bottomInset: getMenuInsets()?.bottom ?? nil)vc.didClose = { [weak self] inif menuSheet == nil {self?.resumeEmulationAndHandleAudio()@@ -1622,6 +1651,7 @@ extension PlayViewController {return falsecase .airPlayScaling:+ //MARK: handleMenuGameSetting.airPlayScalingif item.airPlayScaling != Settings.defalut.airPlayScaling {Settings.defalut.updateExtra(key: ExtraKey.airPlayScaling.rawValue, value: item.airPlayScaling.rawValue)//如果当前正处于AirPlay状态 则更新AirPlay的缩放模式@@ -1630,6 +1660,7 @@ extension PlayViewController {UIView.makeToast(message: R.string.localizable.airPlayScaling() + ": " + item.airPlayScaling.title)case .airPlayLayout:+ //MARK: handleMenuGameSetting.airPlayLayoutif item.airPlayLayout != Settings.defalut.airPlayLayout {Settings.defalut.updateExtra(key: ExtraKey.airPlayLayout.rawValue, value: item.airPlayLayout.rawValue)//如果当前正处于AirPlay状态 则更新AirPlay的布局@@ -1638,6 +1669,7 @@ extension PlayViewController {UIView.makeToast(message: R.string.localizable.airPlayLayout() + ": " + item.airPlayLayout.title)case .toggleAnalog:+ //MARK: handleMenuGameSetting.toggleAnalogupdateAnalogMode(toastAllow: true, toggle: true);}//默认关闭菜单@@ -2088,7 +2120,7 @@ extension PlayViewController {let realm = Database.realmif let coreName = manicEmuCore?.manicCore.name,let skin = realm.objects(Skin.self).where({ $0.fileName == "\(coreName)_FLEX.manicskin" }).first,- let skinUrl = skin.skinData?.filePath,+ let skinUrl = skin.skinData?.filePath,var controllerSkin = ControllerSkin(fileURL: skinUrl) {if enableSwapScreen() {controllerSkin.isSwapScreen = manicGame.swapScreen@@ -2119,6 +2151,12 @@ extension PlayViewController {}//更新3DS画面视图update3DSViews()+ //设置Alert的menuInsets+ if let menuInsets = getMenuInsets() {+ UIView.alertBottomInset = menuInsets.bottom+ } else {+ UIView.alertBottomInset = nil+ }}/// 按照配置开始强制旋转屏幕@@ -2820,7 +2858,7 @@ extension PlayViewController {CheevosPopupView.show(type: .leaderboard,leaderboards: leaderboards.reversed(),gameViewRect: self.gameView.frame,- menuInsets: getMenuInset()) { [weak self] in+ menuInsets: getMenuInsets()) { [weak self] inself?.resumeEmulationAndHandleAudio()}}@@ -2843,7 +2881,7 @@ extension PlayViewController {CheevosPopupView.show(type: .progress,achievements: progressAchievements.reversed(),gameViewRect: self.gameView.frame,- menuInsets: getMenuInset()) { [weak self] in+ menuInsets: getMenuInsets()) { [weak self] inself?.resumeEmulationAndHandleAudio()}}@@ -2867,7 +2905,7 @@ extension PlayViewController {CheevosPopupView.show(type: .challenge,achievements: self.challengeAchievements.reversed(),gameViewRect: self.gameView.frame,- menuInsets: getMenuInset()) { [weak self] in+ menuInsets: getMenuInsets()) { [weak self] inself?.resumeEmulationAndHandleAudio()}}@@ -2875,7 +2913,7 @@ extension PlayViewController {}}- private func getMenuInset() -> UIEdgeInsets? {+ private func getMenuInsets() -> UIEdgeInsets? {var menuInsets: UIEdgeInsets? = nilif let traits = controllerView.controllerSkinTraits, let insets = controllerView.controllerSkin?.menuInsets(for: traits) {func absoluteValue(for inset: Double, dimension: Double) -> Double {diff --git a/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift b/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swiftindex 351386b1..985740c8 100644--- a/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift+++ b/ManicEmu/ManicEmu/Sources/Tools/Extensions/UIViewExtensions.swift@@ -216,6 +216,7 @@ extension UIView {startLoadingTime = nil}+ static var alertBottomInset: CGFloat? = nilprivate static var SheetIdentifiers = [String]()static func makeAlert(identifier: String? = nil,title: String? = nil,@@ -397,7 +398,12 @@ extension UIView {}sheet.set(customView: view).snp.makeConstraints { make in- make.edges.equalToSuperview()+ if let bottomInset = UIView.alertBottomInset, bottomInset > 0, PlayViewController.isGaming {+ make.leading.top.trailing.equalToSuperview()+ make.bottom.equalToSuperview().inset(bottomInset)+ } else {+ make.edges.equalToSuperview()+ }}}if let identifier = identifier {