Skip to content

Commit

Permalink
Merge pull request #21 from PlayCover/2.0-UI
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
JoseMoreville authored Oct 25, 2022
2 parents fad9beb + b9a929e commit d8783b0
Show file tree
Hide file tree
Showing 32 changed files with 1,091 additions and 1,405 deletions.
4 changes: 4 additions & 0 deletions AKInterface-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

83 changes: 83 additions & 0 deletions AKPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// MacPlugin.swift
// AKInterface
//
// Created by Isaac Marovitz on 13/09/2022.
//

import AppKit
import Foundation

class AKPlugin: NSObject, Plugin {
required override init() {
}

var screenCount: Int {
NSScreen.screens.count
}

var mousePoint: CGPoint {
NSApplication.shared.windows.first!.mouseLocationOutsideOfEventStream as CGPoint
}

var windowFrame: CGRect {
NSApplication.shared.windows.first!.frame as CGRect
}

var isMainScreenEqualToFirst: Bool {
return NSScreen.main == NSScreen.screens.first
}

var mainScreenFrame: CGRect {
return NSScreen.main!.frame as CGRect
}

var isFullscreen: Bool {
NSApplication.shared.windows.first!.styleMask.contains(.fullScreen)
}

func hideCursor() {
NSCursor.hide()
}

func unhideCursor() {
NSCursor.unhide()
}

func terminateApplication() {
NSApplication.shared.terminate(self)
}

func eliminateRedundantKeyPressEvents(_ dontIgnore: @escaping() -> Bool) {
NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: { event in
if dontIgnore() {
return event
}
return nil
})
}

func setupMouseButton(_ _up: Int, _ _down: Int, _ dontIgnore: @escaping(Int, Bool, Bool) -> Bool) {
NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask(rawValue: UInt64(_up)), handler: { event in
let isEventWindow = event.window == NSApplication.shared.windows.first!
if dontIgnore(_up, true, isEventWindow) {
return event
}
return nil
})
NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask(rawValue: UInt64(_down)), handler: { event in
if dontIgnore(_up, false, true) {
return event
}
return nil
})
}

func urlForApplicationWithBundleIdentifier(_ value: String) -> URL? {
NSWorkspace.shared.urlForApplication(withBundleIdentifier: value)
}

func setMenuBarVisible(_ visible: Bool) {
NSMenu.setMenuBarVisible(visible)
}
}
249 changes: 216 additions & 33 deletions PlayTools.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions PlayTools.xcodeproj/xcshareddata/xcschemes/PlayTools.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6E84A14B28D0F96D00BF7495"
BuildableName = "AKInterface.bundle"
BlueprintName = "AKInterface"
ReferencedContainer = "container:PlayTools.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
Expand Down
18 changes: 7 additions & 11 deletions PlayTools/Controls/ControlMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import Foundation

let mode = ControlMode.mode

@objc final public class ControlMode: NSObject {
public class ControlMode {

@objc static public let mode = ControlMode()
@objc public var visible: Bool = PlaySettings.shared.gamingMode

@objc static public func isMouseClick(_ event: Any) -> Bool {
return [1, 2].contains(Dynamic(event).type.asInt)
}
static public let mode = ControlMode()
public var visible: Bool = PlaySettings.shared.mouseMapping

func show(_ show: Bool) {
if !editor.editorMode {
Expand All @@ -23,16 +19,16 @@ let mode = ControlMode.mode
if screen.fullscreen {
screen.switchDock(true)
}
if PlaySettings.shared.gamingMode {
Dynamic.NSCursor.unhide()
if PlaySettings.shared.mouseMapping {
AKInterface.shared!.unhideCursor()
disableCursor(1)
}
PlayInput.shared.invalidate()
}
} else {
if visible {
if PlaySettings.shared.gamingMode {
Dynamic.NSCursor.hide()
if PlaySettings.shared.mouseMapping {
AKInterface.shared!.hideCursor()
disableCursor(0)
}
if screen.fullscreen {
Expand Down
45 changes: 38 additions & 7 deletions PlayTools/Controls/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@

import UIKit

extension UIWindow {
class RotateViewController: UIViewController {
static let orientationList: [UIInterfaceOrientation] = [
.landscapeLeft, .portrait, .landscapeRight, .portraitUpsideDown]
static var orientationTraverser = 0

static func rotate() {
orientationTraverser += 1
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
RotateViewController.orientationList[
RotateViewController.orientationTraverser % RotateViewController.orientationList.count]
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .all }
override var modalPresentationStyle: UIModalPresentationStyle { get {.fullScreen} set {} }
}

extension UIApplication {
@objc
func switchEditorMode(_ sender: AnyObject) {
EditorController.shared.switchMode()
Expand All @@ -29,18 +46,32 @@ extension UIWindow {
}
}

extension UIViewController {
@objc
func rotateView(_ sender: AnyObject) {
RotateViewController.rotate()
let viewController = RotateViewController(nibName: nil, bundle: nil)
self.present(viewController, animated: true)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: {
self.dismiss(animated: true)
})
}
}

struct CommandsList {
static let KeymappingToolbox = "keymapping"
}

var keymapping = ["Open/Close Keymapping Editor",
"Delete selected element",
"Upsize selected element",
"Downsize selected element"]
var keymappingSelectors = [#selector(UIWindow.switchEditorMode(_:)),
#selector(UIWindow.removeElement(_:)),
#selector(UIWindow.upscaleElement(_:)),
#selector(UIWindow.downscaleElement(_:))]
"Downsize selected element",
"Rotate display area"]
var keymappingSelectors = [#selector(UIApplication.switchEditorMode(_:)),
#selector(UIApplication.removeElement(_:)),
#selector(UIApplication.upscaleElement(_:)),
#selector(UIApplication.downscaleElement(_:)),
#selector(UIViewController.rotateView(_:))]

class MenuController {
init(with builder: UIMenuBuilder) {
Expand All @@ -51,7 +82,7 @@ class MenuController {

@available(iOS 15.0, *)
class func keymappingMenu() -> UIMenu {
let keyCommands = [ "K", UIKeyCommand.inputDelete, UIKeyCommand.inputUpArrow, UIKeyCommand.inputDownArrow ]
let keyCommands = [ "K", UIKeyCommand.inputDelete, UIKeyCommand.inputUpArrow, UIKeyCommand.inputDownArrow, "R" ]

let arrowKeyChildrenCommands = zip(keyCommands, keymapping).map { (command, btn) in
UIKeyCommand(title: btn,
Expand Down
9 changes: 0 additions & 9 deletions PlayTools/Controls/PTFakeTouch/NSObject+Swizzle.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ +(void)load
[objc_getClass("FBSDisplayMode") swizzleInstanceMethod:@selector(size) withMethod:@selector(hook_size)];
}

if ([[PlaySettings shared] refreshRate] == 120){
[objc_getClass("UnityAppController") swizzleInstanceMethod:@selector(callbackFramerateChange:) withMethod:@selector(hook_callbackFramerateChange:)];
}

[objc_getClass("NSMenuItem") swizzleClassMethod:@selector(enabled) withMethod:@selector(hook_enabled)];

[objc_getClass("IOSViewController") swizzleInstanceMethod:@selector(prefersPointerLocked) withMethod:@selector(hook_prefersPointerLocked)];
Expand All @@ -111,11 +107,6 @@ -(BOOL) hook_prefersPointerLocked {
return false;
}

- (void) hook_callbackFramerateChange:(int)targetFPS {
printf("FPS %d", targetFPS);
[self hook_callbackFramerateChange:120];
}

- (MTLPixelFormat) hook_stencilAttachmentPixelFormat {
return MTLPixelFormatDepth32Float;
}
Expand Down
4 changes: 2 additions & 2 deletions PlayTools/Controls/PTFakeTouch/PTFakeMetaTouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ double ColourDistance(RGB e1, RGB e2);
* @param phase 操作的类别 type of the operation
* @param window key window in which touch event is to happen
*
* @return realid returns the allocated ID for this touch point, or -1 if no such point
* @return deleted whether the system had deleted a previous touch
*/

+ (NSInteger)fakeTouchId:(NSInteger)pointId AtPoint:(CGPoint)point withTouchPhase:(UITouchPhase)phase inWindow:(UIWindow*)window;
+ (NSInteger)fakeTouchId:(NSInteger)pointId AtPoint:(CGPoint)point withTouchPhase:(UITouchPhase)phase inWindow:(UIWindow*)window onView:(UIView*)view;
/**
* Get a not used pointId 获取一个没有使用过的触屏序列号 obtain a never used touch screen sequence number
*
Expand Down
Loading

0 comments on commit d8783b0

Please sign in to comment.