package com.arc.dh.state { import com.arc.dh.util.Data; import com.arc.dh.util.Fonts; import com.arc.dh.util.Sound; import com.arc.dh.util.SoundSystem; import com.arc.flixel.ArcGroup; import com.arc.flixel.ArcSprite; import org.flixel.FlxBitmapText; import org.flixel.FlxG; public class Chapter extends ArcGroup { private static const sprite:Class = Chapter_sprite; public static const badgesSprite:Class = Chapter_badgesSprite; private static const FRAMES_PER_CHAPTER:int = 4; private var _chapter:int; private var _locked:Boolean; private var _text:FlxBitmapText; private var _image:ArcSprite; private var _bar:ArcSprite; private var _badge:ArcSprite; public function Chapter(param1:int) { super(9 + param1 * 50,150); this._chapter = param1 + 1; this._locked = this._chapter > 1 && Data.chapters[param1 - 1][0] == 0; this._image = new ArcSprite(0,0); this._image.loadGraphic(sprite,true,false,39,39); this._image.addAnimation("idle",[FRAMES_PER_CHAPTER * param1]); this._image.addAnimation("hover",[FRAMES_PER_CHAPTER * param1 + 1]); this._image.addAnimation("locked",[FRAMES_PER_CHAPTER * param1 + 2]); this._image.addAnimation("locked_hover",[FRAMES_PER_CHAPTER * param1 + 3]); this._image.play("idle"); this.add(this._image); this._text = new FlxBitmapText(-4,-5,Fonts.font(Fonts.OUTLINE_GRADIENT_S),"CHAPTER " + (param1 + 1),"center",49,true); this.add(this._text); this._bar = new ArcSprite(1,43); this._bar.makeGraphic(37,4,2566914048); this.add(this._bar); this._badge = new ArcSprite(11,40); this._badge.loadGraphic(badgesSprite,true,false,16,9); this._badge.addAnimation("badge",[Data.chapters[param1][1] == 0 ? 4 : Data.chapters[param1][1]]); this._badge.play("badge"); this.add(this._badge); this.update(); } public function hover() : Boolean { return this._image.hover(); } public function getX() : int { return this._image.x + this._image.width / 2; } public function getY() : int { return this._image.y - 1; } override public function update() : void { if(this._image.hover()) { if(this._image.animation != "locked_hover" && this._image.animation != "hover") { SoundSystem.play(Sound.MENU_SELECT); } this._image.play(this._locked ? "locked_hover" : "hover"); if(FlxG.mouse.justPressed()) { if(!this._locked) { SoundSystem.fadeOutMusic(); FlxG.fade(4278190080,0.25,function():void { FlxG.mouse.hide(); FlxG.switchState(new StoryMode(_chapter)); }); } } } else { this._image.play(this._locked ? "locked" : "idle"); } super.update(); } } }