This commit is contained in:
workinghard
2015-04-07 20:01:51 -07:00
parent a3504278d6
commit 7d09aba3ac
13 changed files with 204 additions and 36 deletions

View File

@@ -7,27 +7,41 @@
// //
import Cocoa import Cocoa
import Foundation
class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
@IBOutlet weak var animationsWindow: NSWindow! //let _emptyAnimation: NSMutableDictionary = ["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 1]
@IBOutlet weak var myTableView: NSTableView!
var dataArray: [NSMutableDictionary] = [["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 3, "AnimSpeed": 700, "AnimFrames": 12], /*
var dataArray: [NSMutableDictionary] = [["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 3, "AnimSpeed": 700, "AnimFrames": 12],
["AnimName": "Animation2", "AnimKey": "1=anim2", "AnimDur": 7, "AnimSpeed": 1700, "AnimFrames": 17], ["AnimName": "Animation2", "AnimKey": "1=anim2", "AnimDur": 7, "AnimSpeed": 1700, "AnimFrames": 17],
["AnimName": "Animation3", "AnimKey": "1=anim3", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 22], ["AnimName": "Animation3", "AnimKey": "1=anim3", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 22],
["AnimName": "Animation4", "AnimKey": "1=anim4", "AnimDur": 10, "AnimSpeed": 500, "AnimFrames": 32], ["AnimName": "Animation4", "AnimKey": "1=anim4", "AnimDur": 10, "AnimSpeed": 500, "AnimFrames": 32],
["AnimName": "Animation5", "AnimKey": "1=anim5", "AnimDur": 23, "AnimSpeed": 500, "AnimFrames": 18], ["AnimName": "Animation5", "AnimKey": "1=anim5", "AnimDur": 23, "AnimSpeed": 500, "AnimFrames": 18],
["AnimName": "Animation6", "AnimKey": "1=anim6", "AnimDur": 2, "AnimSpeed": 1000, "AnimFrames": 52]]; ["AnimName": "Animation6", "AnimKey": "1=anim6", "AnimDur": 2, "AnimSpeed": 1000, "AnimFrames": 52]];
*/
var _animationArray: [NSMutableDictionary] = [NSMutableDictionary]();
class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
@IBOutlet weak var myTableView: NSTableView!
var _selectedRow: Int = -1
override func awakeFromNib() {
_animationArray.append(_emptyAnimation)
}
func numberOfRowsInTableView(tableView: NSTableView) -> Int { func numberOfRowsInTableView(tableView: NSTableView) -> Int {
let numberOfRows:Int = dataArray.count let numberOfRows:Int = _animationArray.count
return numberOfRows return numberOfRows
} }
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? { func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
println("Display: \(row)") //println("Display: \(row)")
let object: NSDictionary = dataArray[row] as NSDictionary let object: NSDictionary = _animationArray[row] as NSDictionary
//println(object) //println(object)
let column: String = tableColumn?.identifier as String! let column: String = tableColumn?.identifier as String!
if column == "AnimName" { if column == "AnimName" {
@@ -54,12 +68,67 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
return column return column
} }
func tableViewSelectionDidChange(notification: NSNotification) { func tableViewSelectionDidChange(notification: NSNotification) {
println("klicked") let view: NSTableView = notification.object as NSTableView
_selectedRow = view.selectedRow
//println("klicked \(view.selectedRow)")
} }
func tableView(tableView: NSTableView, setObjectValue object: AnyObject?, forTableColumn tableColumn: NSTableColumn?, row: Int) { func tableView(tableView: NSTableView, setObjectValue object: AnyObject?, forTableColumn tableColumn: NSTableColumn?, row: Int) {
dataArray[row].setObject(object!, forKey: (tableColumn?.identifier)!) let column: String = tableColumn?.identifier as String!
//println("Object: \(object) Key: \((tableColumn?.identifier)!)" )
let value = object! as NSString
if column == "AnimName" {
_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
}
if column == "AnimKey" {
_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
}
if column == "AnimDur" {
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
}
if column == "AnimSpeed" {
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
}
if column == "AnimFrames" {
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
}
}
@IBAction func addNewAnimation(sender: AnyObject) {
_animationArray.append(_emptyAnimation)
myTableView.reloadData()
// println("Adding new Item")
}
@IBAction func delNewAnimation(sender: AnyObject) {
if ( _selectedRow >= 0 ) {
_animationArray.removeAtIndex(_selectedRow)
myTableView.reloadData()
}
// println("Deleting selected Item")
}
@IBAction func moveUpItem(send: AnyObject) {
if ( _selectedRow > 0 ) {
_animationArray.insert(_animationArray[_selectedRow], atIndex: _selectedRow-1)
_animationArray.removeAtIndex(_selectedRow+1)
myTableView.reloadData()
myTableView.selectRowIndexes(NSIndexSet(index: _selectedRow-1), byExtendingSelection: false)
// let save: NSMutableDictionary = dataArray.
}
}
@IBAction func moveDownItem(send: AnyObject) {
if (_selectedRow < _animationArray.count - 1) {
_animationArray.insert(_animationArray[_selectedRow+1], atIndex: _selectedRow)
_animationArray.removeAtIndex(_selectedRow+2)
myTableView.reloadData()
myTableView.selectRowIndexes(NSIndexSet(index: _selectedRow+1), byExtendingSelection: false)
}
} }
/* /*

View File

@@ -8,17 +8,17 @@
import Cocoa import Cocoa
var _animationsWindow: NSWindow = NSWindow()
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow! @IBOutlet weak var window: NSWindow!
@IBOutlet weak var projectWindow: NSWindow! @IBOutlet weak var animationsWindow: NSWindow!
@IBOutlet weak var closeButton: NSButton!
func applicationDidFinishLaunching(aNotification: NSNotification) { func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application // Insert code here to initialize your application
_animationsWindow = animationsWindow
} }
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply { func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
@@ -26,9 +26,5 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return NSApplicationTerminateReply.TerminateNow return NSApplicationTerminateReply.TerminateNow
} }
@IBAction func closeButtonClicked(sender: AnyObject ) {
projectWindow.close()
}
} }

View File

@@ -204,6 +204,36 @@ class GameView: SCNView {
updateButtonVisibility() updateButtonVisibility()
} }
func plusSpeedButtonPressed() {
if ( _playSendDelay <= 3 ) { // 3 seconds slowest fps
_playSendDelay = _playSendDelay + 0.1
updateSpeedText()
}
}
func minusSpeedButtonPressed() {
println(_playSendDelay)
if ( _playSendDelay > 0.2 ) { // 100ms fastest fps
_playSendDelay = _playSendDelay - 0.1
updateSpeedText()
}
}
func updateSpeedText() {
if let rootNode = self.scene?.rootNode {
for childNode in rootNode.childNodes {
let buttonNode: SCNNode = childNode as SCNNode
if buttonNode.name == "mySpeedText" {
let geometry:SCNText = buttonNode.geometry as SCNText
geometry.string = "Speed: \(Int(_playSendDelay*1000)) ms"
}
}
}
}
func playButtonPressed() { func playButtonPressed() {
// Change the button from Play to Pause // Change the button from Play to Pause
let myPauseButtonNode: SCNNode = self.scene!.rootNode.childNodeWithName("myPauseButton", recursively: true)! let myPauseButtonNode: SCNNode = self.scene!.rootNode.childNodeWithName("myPauseButton", recursively: true)!
@@ -226,6 +256,10 @@ class GameView: SCNView {
_playAllFrames = false _playAllFrames = false
} }
func openAnimationWindow() {
_animationsWindow.setIsVisible(true)
}
override func rightMouseDown(theEvent: NSEvent) { override func rightMouseDown(theEvent: NSEvent) {
let p = self.convertPoint(theEvent.locationInWindow, fromView: nil) let p = self.convertPoint(theEvent.locationInWindow, fromView: nil)
@@ -305,6 +339,15 @@ class GameView: SCNView {
} }
if clickedNode.name == "myLastFrameButton" { if clickedNode.name == "myLastFrameButton" {
lastButtonPressed() lastButtonPressed()
}
if clickedNode.name == "myPlusSpeedButton" {
plusSpeedButtonPressed()
}
if clickedNode.name == "myMinusSpeedButton" {
minusSpeedButtonPressed()
}
if clickedNode.name == "myMngAnimationsButton" {
openAnimationWindow()
} }
if clickedNode.name == "myColorBar" || clickedNode.name == "myArrows" { if clickedNode.name == "myColorBar" || clickedNode.name == "myArrows" {
let colorInt = Int(round(relativeBarPosition - theEvent.locationInWindow.y)) let colorInt = Int(round(relativeBarPosition - theEvent.locationInWindow.y))

View File

@@ -9,10 +9,11 @@
import SceneKit import SceneKit
import QuartzCore import QuartzCore
var myFrameCount: UInt32 = 1; var myFrameCount: UInt32 = 1;
var myMaxFrameCount: UInt32 = 1; var myMaxFrameCount: UInt32 = 1;
var myFrames: NSMutableData = NSMutableData() var myFrames: NSMutableData = NSMutableData() // == byte[] array
var _emptyAnimation: NSMutableDictionary = ["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 1, "AnimData": myFrames]
let emptyFrame: [Byte] = [ let emptyFrame: [Byte] = [
255,255,255,255, 255,255,255,255,

View File

@@ -1,38 +1,45 @@
{ {
"images" : [ "images" : [
{ {
"idiom" : "mac",
"size" : "16x16", "size" : "16x16",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-16.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "mac",
"size" : "16x16", "size" : "16x16",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-32.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "mac",
"size" : "32x32", "size" : "32x32",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-32-1.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "mac",
"size" : "32x32", "size" : "32x32",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-64.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "mac",
"size" : "128x128", "size" : "128x128",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-128.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "mac",
"size" : "128x128", "size" : "128x128",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-256.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "mac",
"size" : "256x256", "size" : "256x256",
"idiom" : "mac",
"filename" : "Cube4Fun-Icon-256-1.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@@ -80,6 +80,42 @@ class PrimitivesScene: SCNScene {
} }
self.rootNode.addChildNode(lastFrameImageNode) self.rootNode.addChildNode(lastFrameImageNode)
}
func createSpeedButtons() {
// Frame
let textSpeed = SCNText(string: "Speed: \(Int(_playSendDelay*1000)) ms", extrusionDepth: 0)
textSpeed.font = NSFont(name: "Arial", size: 1.2)
let textSpeedNode = SCNNode(geometry: textSpeed)
textSpeedNode.name = "mySpeedText"
textSpeedNode.position = SCNVector3(x:-20.0 , y: 9.7, z: 0.0)
self.rootNode.addChildNode(textSpeedNode)
// SpeedUp - Button
let plusSpeedImage = SCNPlane(width: 1.7, height: 1.7)
plusSpeedImage.firstMaterial?.diffuse.contents = NSImage(named: "list-add-2.png")
let plusSpeedImageNode = SCNNode(geometry: plusSpeedImage)
plusSpeedImageNode.name = "myPlusSpeedButton"
plusSpeedImageNode.position = SCNVector3(x:-16.5, y:8, z:0)
self.rootNode.addChildNode(plusSpeedImageNode)
// SpeedDown - Button
let minusSpeedImage = SCNPlane(width: 1.7, height: 1.7)
minusSpeedImage.firstMaterial?.diffuse.contents = NSImage(named: "list-remove-2.png")
let minusSpeedImageNode = SCNNode(geometry: minusSpeedImage)
minusSpeedImageNode.name = "myMinusSpeedButton"
minusSpeedImageNode.position = SCNVector3(x:-18.7, y:8, z:0)
self.rootNode.addChildNode(minusSpeedImageNode)
}
func createFrameButtons() {
let textFrame = SCNText(string: "Frame: \(myFrameCount)/\(myMaxFrameCount)", extrusionDepth: 0)
textFrame.font = NSFont(name: "Arial", size: 1.2)
let textFrameNode = SCNNode(geometry: textFrame)
textFrameNode.name = "myFrameText"
textFrameNode.position = SCNVector3(x:-20.0 , y: 13.7, z: 0.0)
self.rootNode.addChildNode(textFrameNode)
// AddFrame - Button // AddFrame - Button
let addFrameImage = SCNPlane(width: 1.7, height: 1.7) let addFrameImage = SCNPlane(width: 1.7, height: 1.7)
addFrameImage.firstMaterial?.diffuse.contents = NSImage(named: "list-add-2.png") addFrameImage.firstMaterial?.diffuse.contents = NSImage(named: "list-add-2.png")
@@ -99,7 +135,23 @@ class PrimitivesScene: SCNScene {
delFrameImageNode.hidden = true delFrameImageNode.hidden = true
} }
self.rootNode.addChildNode(delFrameImageNode) self.rootNode.addChildNode(delFrameImageNode)
}
func createOpenAnimations() {
let textAnimations = SCNText(string: "List Animations", extrusionDepth: 0)
textAnimations.font = NSFont(name: "Arial", size: 1.2)
let textAnimationsNode = SCNNode(geometry: textAnimations)
textAnimationsNode.name = "myAnimationsText"
textAnimationsNode.position = SCNVector3(x:-20.0 , y: 5.7, z: 0.0)
self.rootNode.addChildNode(textAnimationsNode)
// Manage Animations - Button
let mngAnimationsImage = SCNPlane(width: 1.7, height: 1.7)
mngAnimationsImage.firstMaterial?.diffuse.contents = NSImage(named: "view-sidetree.png")
let mngAnimationsImageNode = SCNNode(geometry: mngAnimationsImage)
mngAnimationsImageNode.name = "myMngAnimationsButton"
mngAnimationsImageNode.position = SCNVector3(x:-16.5, y:4, z:0)
self.rootNode.addChildNode(mngAnimationsImageNode)
} }
override init() { override init() {
@@ -134,17 +186,17 @@ class PrimitivesScene: SCNScene {
self.rootNode.addChildNode(textNode) self.rootNode.addChildNode(textNode)
// Frame // Frame
let textFrame = SCNText(string: "Frame: \(myFrameCount)/\(myMaxFrameCount)", extrusionDepth: 0) createFrameButtons()
textFrame.font = NSFont(name: "Arial", size: 1.2)
let textFrameNode = SCNNode(geometry: textFrame)
textFrameNode.name = "myFrameText"
textFrameNode.position = SCNVector3(x:-20.0 , y: 13.7, z: 0.0)
self.rootNode.addChildNode(textFrameNode)
// Action Buttons // Action Buttons
createPlayback() createPlayback()
// Speed Buttons
createSpeedButtons()
// Open Animation Button
createOpenAnimations()
// color picker // color picker
let colorBar = SCNPlane(width: 3, height: 16) let colorBar = SCNPlane(width: 3, height: 16)
colorBar.firstMaterial?.diffuse.contents = NSImage(named: "Gradient2.png") colorBar.firstMaterial?.diffuse.contents = NSImage(named: "Gradient2.png")