130 lines
3.3 KiB
ActionScript
130 lines
3.3 KiB
ActionScript
package com.arc.flixel
|
|
{
|
|
import com.arc.dh.util.Sound;
|
|
import com.arc.dh.util.SoundSystem;
|
|
import org.flixel.FlxG;
|
|
|
|
public class ArcButton extends ArcSprite
|
|
{
|
|
|
|
private var _state:String = "inactive";
|
|
|
|
private var _group:ArcButtonGroup;
|
|
|
|
private var _selectable:Boolean = true;
|
|
|
|
private var _callbackFunction:Function;
|
|
|
|
private var _updateFunction:Function;
|
|
|
|
private var _hoverable:Boolean = true;
|
|
|
|
public function ArcButton(param1:Number, param2:Number, param3:int, param4:int, param5:Class)
|
|
{
|
|
super(param1,param2);
|
|
loadGraphic(param5,true,false,param3,param4);
|
|
addAnimation("inactive",[0],0,false);
|
|
addAnimation("hover",[1],0,false);
|
|
addAnimation("selected",[2],0,false);
|
|
}
|
|
|
|
override public function update() : void
|
|
{
|
|
if(this._state != ButtonState.SELECTED)
|
|
{
|
|
if(hover() && exists && alive && visible)
|
|
{
|
|
if(FlxG.mouse.justPressed())
|
|
{
|
|
this.select(true,true);
|
|
}
|
|
else if(this._hoverable)
|
|
{
|
|
if(this._state != ButtonState.HOVER)
|
|
{
|
|
SoundSystem.play(Sound.MENU_SELECT);
|
|
}
|
|
this._state = ButtonState.HOVER;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this._state = ButtonState.INACTIVE;
|
|
}
|
|
}
|
|
play(this._state);
|
|
if(this._updateFunction != null)
|
|
{
|
|
this._updateFunction();
|
|
}
|
|
super.update();
|
|
}
|
|
|
|
public function hoverable(param1:Boolean) : ArcButton
|
|
{
|
|
this._hoverable = param1;
|
|
return this;
|
|
}
|
|
|
|
public function select(param1:Boolean = true, param2:Boolean = false) : ArcButton
|
|
{
|
|
if(!param1)
|
|
{
|
|
return this;
|
|
}
|
|
if(this._group != null && this._selectable)
|
|
{
|
|
this._group.unselect();
|
|
}
|
|
if(this._callbackFunction != null && param2)
|
|
{
|
|
this._callbackFunction();
|
|
}
|
|
if(this._selectable)
|
|
{
|
|
this._state = ButtonState.SELECTED;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public function unselect() : void
|
|
{
|
|
this._state = ButtonState.INACTIVE;
|
|
}
|
|
|
|
public function setGroup(param1:ArcButtonGroup, param2:Boolean = false) : ArcButton
|
|
{
|
|
this._group = param1;
|
|
if(param2)
|
|
{
|
|
param1.addButton(this);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public function selectable(param1:Boolean) : ArcButton
|
|
{
|
|
this._selectable = param1;
|
|
return this;
|
|
}
|
|
|
|
public function callback(param1:Function) : ArcButton
|
|
{
|
|
this._callbackFunction = param1;
|
|
return this;
|
|
}
|
|
|
|
public function setUpdate(param1:Function) : ArcButton
|
|
{
|
|
this._updateFunction = param1;
|
|
return this;
|
|
}
|
|
|
|
public function get selected() : Boolean
|
|
{
|
|
return this._state == ButtonState.SELECTED;
|
|
}
|
|
}
|
|
}
|
|
|