From 736560ffdddd0ecd4c148f44ea75beebe33eb1a9 Mon Sep 17 00:00:00 2001 From: workinghard Date: Sun, 10 May 2015 00:09:50 -0700 Subject: [PATCH] a --- Cube4Fun/Base.lproj/MainMenu.xib | 5 ++++ Cube4Fun/src/Animations.swift | 38 +++++++++++++++++++------ Cube4Fun/src/AnimationsController.swift | 4 ++- Cube4Fun/src/AppDelegate.swift | 10 +++++++ Cube4Fun/src/GameView.swift | 2 ++ 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Cube4Fun/Base.lproj/MainMenu.xib b/Cube4Fun/Base.lproj/MainMenu.xib index c40167f..1a22a74 100644 --- a/Cube4Fun/Base.lproj/MainMenu.xib +++ b/Cube4Fun/Base.lproj/MainMenu.xib @@ -149,6 +149,11 @@ + + + + + diff --git a/Cube4Fun/src/Animations.swift b/Cube4Fun/src/Animations.swift index 1826070..577e3e6 100644 --- a/Cube4Fun/src/Animations.swift +++ b/Cube4Fun/src/Animations.swift @@ -188,6 +188,7 @@ class Animations: NSObject { _animationArray.removeAtIndex(_animationSelected) if ( _animationSelected == 0 && _animationArray.count == 0 ) { // last Frame self.addAnimation() + self.setSelectedAnimationID(self.getSelectedAnimationID()-1) } } func moveUpSelected() { @@ -205,7 +206,7 @@ class Animations: NSObject { func addAnimation() { _animationArray.append(self.newAnimation()) - println("append Animation count: \(_animationArray.count)") + println("append Animation. count: \(_animationArray.count)") } func newAnimation() -> (NSMutableDictionary) { println("create new animation") @@ -226,20 +227,40 @@ class Animations: NSObject { myData.length = myLength - 64 // remove one frame } } - /* + func insertDisplFrame() { + // Insert empty frame at the current position + // Get Array -// var myData = self.getAnimDataSelected() var myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData + var myDataBytes = self.getAnimDataSelected() + //var myData: [UInt8] = [UInt8]() // Get startPositions of the selected frame var frameStartPos = (self.getAnimationFrameID()-1)*64 - // Insert empty frame at this position - for index in 0...64 { - myData.insert(_emptyFrame[index], atIndex: frameStartPos) - } + + // Append one empty frame at the end + self.addFrame() + + var lastArrPos: Int = myData.length - 1 + println("Framestart: \(frameStartPos)") + println("Framelength: \(lastArrPos)") + + // copy frames + while ( lastArrPos >= frameStartPos + 64) { + // myDataBytes[lastArrPos] = myDataBytes[lastArrPos-64] + let myByte: [UInt8] = [myDataBytes[lastArrPos-64]] + let bytePosition = NSMakeRange(lastArrPos, 1) + myData.replaceBytesInRange(bytePosition, withBytes: myByte) + --lastArrPos + } + + // clear current frame + self.clearLEDColor() } + + /* func deleteDisplFrame() { // Get Array let myData = self.getAnimDataSelected() @@ -249,7 +270,8 @@ class Animations: NSObject { myData.removeAtIndex(frameStartPos) } } -*/ + */ + func animationSpeedInt() -> Int { diff --git a/Cube4Fun/src/AnimationsController.swift b/Cube4Fun/src/AnimationsController.swift index 02b8c4f..5a163af 100644 --- a/Cube4Fun/src/AnimationsController.swift +++ b/Cube4Fun/src/AnimationsController.swift @@ -87,6 +87,7 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate func tableViewSelectionDidChange(notification: NSNotification) { let view: NSTableView = notification.object as! NSTableView + println("klicked \(view.selectedRow)") __animations.setSelectedAnimationID(view.selectedRow) _gameView.resetView() @@ -96,7 +97,7 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate //_selectedAnimation = view.selectedRow - //println("klicked \(view.selectedRow)") + println("klicked \(view.selectedRow)") } func tableView(tableView: NSTableView, setObjectValue object: AnyObject?, forTableColumn tableColumn: NSTableColumn?, row: Int) { @@ -135,6 +136,7 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate @IBAction func delNewAnimation(sender: AnyObject) { __animations.deleteSelected() + myTableView.selectRowIndexes(NSIndexSet(index: __animations.getSelectedAnimationID()-1), byExtendingSelection: false) myTableView.reloadData() } diff --git a/Cube4Fun/src/AppDelegate.swift b/Cube4Fun/src/AppDelegate.swift index a09c1c1..9259ab0 100644 --- a/Cube4Fun/src/AppDelegate.swift +++ b/Cube4Fun/src/AppDelegate.swift @@ -175,4 +175,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate { __animations.sendFrame() } + @IBAction func cmdInsertPressed(send: AnyObject) { + // Insert one new frame at the current position + __animations.insertDisplFrame() + // Update visual + _gameView.updateLEDFrame() + _gameView.updateButtonVisibility() + + // Update on a hardware + __animations.sendFrame() + } } diff --git a/Cube4Fun/src/GameView.swift b/Cube4Fun/src/GameView.swift index a448128..68cb434 100644 --- a/Cube4Fun/src/GameView.swift +++ b/Cube4Fun/src/GameView.swift @@ -193,6 +193,8 @@ class GameView: SCNView { // remove one frame from the data array // TODO! + self.prevButtonPressed() + // Remove frame __animations.removeFrame() // if __animations.getAnimationFrameCount() > 1 {