Progression4をControllerとして使う練習4
Progression4の練習。4
シーンとかページとかとはちょっと違う構成、
例えば3D空間を移動するなどの時に
Progression4をControllerとして使うとすると、
どうしたらいいんだろう。
試行錯誤中
うーん、はやくもコードがぐちゃぐちゃ。
要整理。
Progression4のいいところがぜんぜん活用できてないような。
/**
* Copyright umhr ( http://wonderfl.net/user/umhr )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oTz7
*/
/*
Progression4の練習。4
シーンとかページとかとはちょっと違う構成、
例えば3D空間を移動するなどの時に
Progression4をControllerとして使うとすると、
どうしたらいいんだろう。
試行錯誤中
うーん、はやくもコードがぐちゃぐちゃ。
要整理。
Progression4のいいところがぜんぜん活用できてないような。
*/
package {
import flash.display.*;
import flash.events.MouseEvent;
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
import jp.progression.*;
import jp.progression.config.*;
import jp.progression.debug.*;
import jp.progression.events.*;
import jp.progression.executors.ExecutorObjectState;
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 30)]
public class Main extends Sprite {
public var manager:Progression;
private var _view:View;
private var _tf:TextField;
private var _data:Data = new Data();
public function Main() {
stage.transform.perspectiveProjection = new PerspectiveProjection();
stage.transform.perspectiveProjection.projectionCenter = new Point(465/2,465/2);
Progression.initialize( new BasicAppConfig() );
manager = new Progression( "index", stage, IndexScene );
_data.s1 = 0;
//Debugger.addTarget( manager );
addView();
manager.goto( manager.root.sceneId );
manager.addEventListener(ProcessEvent.PROCESS_START, onProcessStart);
}
private function addView():void{
_view = new View();
_view.x = 465/2;
_view.y = 465/2;
this.addChild(_view);
stage.addEventListener(MouseEvent.CLICK, clickHandler);
_tf = new TextField();
_tf.defaultTextFormat = new TextFormat("_sans", 18, 0xFFFFFF);
_tf.text = "index";
_tf.autoSize = "left";
this.addChild(_tf);
}
private function clickHandler(e:MouseEvent):void {
if (manager.state > ExecutorObjectState.IDLING) {
manager.stop();
}
var arr:Array = String(e.target.name).split("/");
if (arr.length > 0) {
_data.setScene(arr);
if(arr.length == 1){
manager.goto(manager.root.scenes[int(arr[0])].sceneId);
}else if(arr.length == 2){
manager.goto(manager.root.scenes[int(arr[0])].scenes[int(arr[1])].sceneId);
}else if(arr.length == 3){
manager.goto(manager.root.scenes[int(arr[0])].scenes[int(arr[1])].scenes[int(arr[2])].sceneId);
}
}
}
private function onProcessStart(event:ProcessEvent):void {
_tf.text = String(manager.destinedSceneId);
_view.pitchStep(_data);
}
}
}
class Data {
private var _s1:int = -1;
private var _s2:int = -1;
private var _s3:int = -1;
private var _prevS1:int = -1;
private var _prevS2:int = -1;
private var _prevS3:int = -1;
public function Data() { };
public function setScene(array:Array):void {
_prevS1 = _s1;
_prevS2 = _s2;
_prevS3 = _s3;
_s1 = int(array[0]);
_s2 = (array.length >= 2)?int(array[1]): -1;
_s3 = (array.length >= 3)?int(array[2]): -1;
}
public function getScene():Array {
return [_s1, _s2, _s3];
}
public function get s1():int { return _s1 };
public function set s1(value:int):void {
_prevS1 = _s1;
_s1 = value;
}
public function get prevS1():int { return _prevS1 };
public function get s2():int { return _s2 };
public function set s2(value:int):void {
_prevS2 = _s2;
_s2 = value;
}
public function get prevS2():int { return _prevS2 };
public function get s3():int { return _s3 };
public function set s3(value:int):void {
_prevS3 = _s3;
_s3 = value;
}
public function get prevS3():int { return _prevS3 };
}
import jp.progression.casts.*;
import jp.progression.commands.*;
import jp.progression.commands.display.*;
import jp.progression.commands.lists.*;
import jp.progression.commands.managers.Goto;
import jp.progression.commands.net.*;
import jp.progression.commands.tweens.*;
import jp.progression.data.*;
import jp.progression.events.*;
import jp.progression.executors.ExecutorObjectState;
import jp.progression.scenes.*;
class IndexScene extends SceneObject {
public function IndexScene() {
var sp:CastSprite = new CastSprite();
sp.id = "sqIndex";
}
protected override function atSceneLoad():void {
addCommand(
new AddChild( container, "sqIndex" ),
function():void {
for (var i:int = 0; i < 6; i++) {
var SO:SceneObject = new SceneObject("s" + String(i));
addScene(SO);
for (var j:int = 0; j < 3; j++) {
var SO3rd:SceneObject = new SceneObject("t" + String(j));
SO.addScene(SO3rd);
for (var k:int = 0; k < 6; k++) {
SO3rd.addScene(new SceneObject("u" + String(k)));
}
}
}
}
);
}
protected override function atSceneInit():void {
addCommand();
}
protected override function atSceneGoto():void {
addCommand();
}
}
import flash.display.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;
import flash.display.Sprite;
class View extends Sprite{
private var _canvas:ViewSprite1st;
private var _t:ITween;
public function View():void{
_canvas = new ViewSprite1st();
this.addChild(_canvas);
}
public function pitchStep(_data:Data):void {
var step:int = _data.s1;
var sNum:int = _data.s2;
if (_data.prevS1 == _data.s1) {
_canvas.select(_data);
}else{
var degree:Number = (_data.s1/6)*360;
if(((_data.prevS1/6)*360-degree)<-180){
degree = -360+degree;
}else if (((_data.prevS1 / 6) * 360 - degree) > 180) {
degree = 360+degree;
}
if (_t != null) {
_t.stop();
if(_canvas.rotationY-degree > 180){
degree = 360+degree;
}
}
_t = BetweenAS3.serial(
BetweenAS3.tween(_canvas, { depth:1}, null, 0.3, Expo.easeIn),
BetweenAS3.tween(_canvas, { rotationY:degree}, null, 0.4),
BetweenAS3.tween(_canvas, { depth:0}, null, 0.3, Expo.easeIn)
);
_t.onComplete = function():void {
_canvas.rotationY = (degree + 360) % 360;
_canvas.select(_data);
};
_t.play();
}
}
}
import flash.geom.PerspectiveProjection;
import flash.geom.Point;
import flash.geom.Vector3D;
import flash.geom.Matrix;
import flash.events.Event;
class ViewSprite1st extends Sprite{
private var _sprites:Array;
private var _rotationY:Number = 0;
private var _depth:Number = 0;
public function ViewSprite1st():void{
this.addEventListener(Event.ADDED_TO_STAGE,onStage);
}
private function onStage(event:Event):void{
this.removeEventListener(Event.ADDED_TO_STAGE,onStage);
this.z = 0;
_sprites = [];
var colors:Array = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF];
for (var i:int = 0; i < 6; i++) {
_sprites[i] = new ViewSprite2nd(i);
this.addChild(_sprites[i]);
}
rotationY = 0;
}
public function select(_data:Data):void {
if( _data.prevS1 != _data.s1){
_sprites[_data.prevS1].select(_data);
}
_sprites[_data.s1].select(_data);
}
public function get depth():Number{
return _depth;
}
public function set depth(value:Number):void{
_depth = value;
rotationY = _rotationY;
}
override public function get rotationY():Number{
return _rotationY;
}
override public function set rotationY(value:Number):void{
_rotationY = (value+360)%360;
var n:int = _sprites.length;
for (var i:int = 0; i < n; i++) {
_sprites[i].x = Math.cos(Math.PI*(i/3+(90-_rotationY)/180))*350*(1+(1-_depth)/3.2);
_sprites[i].z = Math.sin(Math.PI*(i/3+(90-_rotationY)/180))*350*_depth;
_sprites[i].rotationY = ((((360-360*i/6+_rotationY))%180+90)%180-90)*_depth;
}
zSort(this);
}
private function zSort(target:DisplayObjectContainer):void {
if(!target.root){return};
var n:int = target.numChildren;
var array:Array = [];
var reference:Array = [];
for (var i:int = 0; i < n; i++) {
if (target.getChildAt(i).transform.matrix3D) {
var poz:Vector3D = target.getChildAt(i).transform.getRelativeMatrix3D(this.root.stage).position;
var point:Point = stage.transform.perspectiveProjection.projectionCenter;
array[i] = poz.subtract(new Vector3D(point.x, point.y, -stage.transform.perspectiveProjection.focalLength)).length;
reference[i] = target.getChildAt(i);
}
}
var temp:Array = array.sort(Array.NUMERIC | Array.RETURNINDEXEDARRAY);
for (i = 0; i < n; i++) {
if (target.getChildAt(i).transform.matrix3D) {
target.setChildIndex(reference[temp[i]],0);
if(reference[temp[i]].numChildren > 1){
zSort(reference[temp[i]]);
}
}
}
var s:int = Math.round(_rotationY / 60) % 6;
for (i = 0; i < n; i++) {
if(_sprites[i].z == 0){
_sprites[i].visible = (Math.abs(s-i)<=1 || Math.abs(s-i) == 5);
}else{
_sprites[i].visible = (_sprites[i].z > 0);
}
}
}
}
class ViewSprite2nd extends Sprite {
private var _colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF];
private var _btns:Array = [];
private var _contents:Array = [];
public function ViewSprite2nd(num:int):void {
this.graphics.lineStyle(3,0xFFFFFF);
this.graphics.beginGradientFill("linear", [_colors[num], 0x000000], [1, 1], [0x00, 0xFF], new Matrix(0.7, 0, -1, 0.7));
this.graphics.drawRect(-190,-190,380,380);
this.graphics.endFill();
this.name = String(num);
addContents(num);
}
private function addContents(s1num:int):void {
for (var i:int = 0; i < 3; i++) {
_btns[i] = new Sprite();
_btns[i].graphics.lineStyle(3,0x666666);
_btns[i].graphics.beginGradientFill("linear", [_colors[i], 0xFFFFFF], [1, 1], [0x00, 0xFF], new Matrix(0.7, 0, -1, 0.7));
_btns[i].graphics.drawRect(0,0,100,20);
_btns[i].graphics.endFill();
_btns[i].name = String(s1num) + "/" + i;
_btns[i].x = i * 110 - 110 - 55;
_btns[i].y = -170;
this.addChild(_btns[i]);
_contents[i] = new ViewSprite3rd(s1num, i);
this.addChild(_contents[i]);
}
}
public function select(_data:Data):void {
if(_data.s1 == int(this.name) && _data.s2 > -1){
_contents[_data.s2].visible = true;
_contents[_data.s2].select(_data);
}
if (_data.prevS1 == int(this.name)) {
if((_data.prevS1 != _data.s1 || _data.prevS2 != _data.s2) && _data.prevS2 > -1) {
_contents[_data.prevS2].visible = false;
_contents[_data.prevS2].select(_data);
}
}
}
}
class ViewSprite3rd extends Sprite {
private var _colors:Array = [0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF];
private var _btns:Array = [];
private var _contents:Array = [];
public function ViewSprite3rd(s1num:int,s2num:int):void {
this.graphics.lineStyle(3,0xFFFFFF);
this.graphics.beginGradientFill("linear", [_colors[s2num], 0xFFFFFF], [1, 1], [0x00, 0xFF], new Matrix(0.7, 0, -1, 0.7));
this.graphics.drawRect(0,0,100,320);
this.graphics.endFill();
this.x = s2num * 110 - 110 - 55;
this.y = -170 + 25;
this.visible = false;
this.name = String(s1num) + "/" + s2num;
addContents(s1num,s2num);
}
private function addContents(s1num:int,s2num:int):void {
for (var i:int = 0; i < 6; i++) {
_btns[i] = new Sprite();
_btns[i].graphics.lineStyle(3, 0x666666);
_btns[i].graphics.beginGradientFill("linear", [_colors[i], 0xFFFFFF], [1, 1], [0x00, 0xFF], new Matrix(0.7, 0, -1, 0.7));
_btns[i].graphics.drawRect(0, 0, 30, 45);
_btns[i].graphics.endFill();
_btns[i].name = String(s1num) + "/" + String(s2num) + "/" + i;
_btns[i].x = 5;
_btns[i].y = 5 + i * 53;
this.addChild(_btns[i]);
_contents[i] = new Sprite();
_contents[i].graphics.lineStyle(3, 0xFFFFFF);
_contents[i].graphics.beginGradientFill("linear", [_colors[i], 0xFFFFFF], [1, 1], [0x00, 0xFF], new Matrix(0.7, 0, -1, 0.7));
_contents[i].graphics.drawRect(0, 0, 55, 45);
_contents[i].graphics.endFill();
_contents[i].name = String(s1num) + "/" + String(s2num) + "/" + i;
_contents[i].x = 40;
_contents[i].y = 5 + i * 53;
_contents[i].visible = false;
this.addChild(_contents[i]);
}
}
public function select(_data:Data):void {
if (_data.s3 != _data.prevS3) {
if (_data.s3 > -1) {
_contents[_data.s3].visible = true;
}
if (_data.prevS3 > -1) {
_contents[_data.prevS3].visible = false;
}
}
}
}