2013年2月5日火曜日

Feathers ScreenExample 作成2

MainMenuScreen.as
package screens
{
 import feathers.controls.Header;
 import feathers.controls.List;
 import feathers.controls.Screen;
 import feathers.data.ListCollection;
 import feathers.skins.StandardIcons;

 import starling.events.Event;
 import starling.textures.Texture;

 public class MainMenuScreen extends Screen
 {
  public static const SHOW_SUB1_SCREEN:String = "showSub1Screen";
  public static const SHOW_SUB2_SCREEN:String = "showSub2Screen";

  private var _header:Header;
  private var _list:List;

  public function MainMenuScreen()
  {
   super();
  }

  override protected function initialize():void
  {
   this._header = new Header();
   this._header.title = "Screen Test";
   this.addChild(this._header);

   this._list = new List();
   this._list.dataProvider = new ListCollection(
    [
    { text: "Sub 1", event: SHOW_SUB1_SCREEN },
    { text: "Sub 2", event: SHOW_SUB2_SCREEN },
    ]);
   this._list.itemRendererProperties.labelField = "text";
   this._list.addEventListener(Event.CHANGE,list_changeHandler);
   this._list.itemRendererProperties.accessorySourceFunction = accessorySourceFunction;
   this.addChild(this._list);
  }

  override protected function draw():void
  {
   this._header.width = this.actualWidth;
   this._header.validate();

   this._list.y = this._header.height;
   this._list.width = this.actualWidth;
   this._list.height = this.actualHeight - this._list.y;
  }

  private function accessorySourceFunction(item:Object):Texture
  {
   return StandardIcons.listDrillDownAccessoryTexture;
  }

  private function list_changeHandler(event:Event):void
  {
   const eventType:String = this._list.selectedItem.event as String;
   this.dispatchEventWith(eventType);
  }
 }
}
Sub1Screen.as
package screens
{
 import feathers.controls.Button;
 import feathers.controls.Header;
 import feathers.controls.Screen;
 import feathers.controls.ScrollContainer;
 import feathers.layout.HorizontalLayout;

 import starling.display.DisplayObject;
 import starling.display.Quad;
 import starling.events.Event;

 public class Sub1Screen extends Screen
 {
  private var _container:ScrollContainer;
  private var _header:Header;
  private var _backButton:Button;
  private var _settingsButton:Button;

  public var horizontalAlign:String = HorizontalLayout.HORIZONTAL_ALIGN_LEFT;
  public var verticalAlign:String = HorizontalLayout.VERTICAL_ALIGN_TOP;
  public var gap:Number = 2;
  public var paddingTop:Number = 0;
  public var paddingRight:Number = 0;
  public var paddingBottom:Number = 0;
  public var paddingLeft:Number = 0;

  public function Sub1Screen()
  {
   super();
  }

  override protected function initialize():void
  {
   const layout:HorizontalLayout = new HorizontalLayout();
   layout.gap = this.gap;
   layout.paddingTop = this.paddingTop;
   layout.paddingRight = this.paddingRight;
   layout.paddingBottom = this.paddingBottom;
   layout.paddingLeft = this.paddingLeft;
   layout.horizontalAlign = this.horizontalAlign;
   layout.verticalAlign = this.verticalAlign;

   this._container = new ScrollContainer();
   this._container.layout = layout;
   this._container.horizontalScrollPolicy = ScrollContainer.SCROLL_POLICY_ON;
   this._container.snapScrollPositionsToPixels = true;
   this.addChild(this._container);

   this._header = new Header();
   this._header.title = "Sub1 Screen";
   this.addChild(this._header);

   this._backButton = new Button();
   this._backButton.label = "Back";
   this._backButton.addEventListener(Event.TRIGGERED, backButton_triggeredHandler);

   this._header.leftItems = new 
    [
    this._backButton
    ];

   this.backButtonHandler = this.onBackButton;

   var redQuad:Quad = new Quad(100,100,0xff0000);
   var greenQuad:Quad = new Quad(100,100,0x00ff00);
   var blueQuad:Quad = new Quad(100,100,0x0000ff);

   this._container.addChild(redQuad);
   this._container.addChild(greenQuad);
   this._container.addChild(blueQuad);
  }

  override protected function draw():void
  {
   this._header.width = this.actualWidth;
   this._header.validate();

   this._container.y = this._header.height;
   this._container.width = this.actualWidth;
   this._container.height = this.actualHeight - this._container.y;
  }

  private function onBackButton():void
  {
   this.owner.showScreen(Main.MAIN_MENU);
  }

  private function backButton_triggeredHandler(event:Event):void
  {
   this.onBackButton();
  }
 }
}

0 件のコメント:

コメントを投稿