294 lines
9.2 KiB
ActionScript
294 lines
9.2 KiB
ActionScript
package com.arc.dh.menu
|
|
{
|
|
import com.arc.dh.state.Tooltip;
|
|
import com.arc.dh.state.UI;
|
|
import com.arc.dh.util.Data;
|
|
import com.arc.dh.util.DataSerializer;
|
|
import com.arc.flixel.ArcButton;
|
|
import com.arc.flixel.ArcButtonGroup;
|
|
import com.arc.flixel.ArcGroup;
|
|
import org.flixel.FlxG;
|
|
import org.flixel.FlxPoint;
|
|
|
|
public class Menu extends ArcGroup
|
|
{
|
|
|
|
public static var tooltip:Tooltip;
|
|
|
|
public static const optionsButton:Class = Menu_optionsButton;
|
|
|
|
public static const backButton:Class = Menu_backButton;
|
|
|
|
public static const closeButton:Class = Menu_closeButton;
|
|
|
|
private static const FADE_SPEED:int = 7;
|
|
|
|
public static var hovering:Boolean = false;
|
|
|
|
private var spriteCharacterButton:Class;
|
|
|
|
private var spriteStatisticsButton:Class;
|
|
|
|
private var _pane:MenuPane;
|
|
|
|
private var _paneCharacter:MenuPane;
|
|
|
|
private var _paneStatistics:MenuPane;
|
|
|
|
private var _paneMessageLog:MenuPane;
|
|
|
|
private var _buttons:ArcButtonGroup;
|
|
|
|
private var _open:Boolean = false;
|
|
|
|
private var _fading:Boolean = false;
|
|
|
|
private var _characterButton:ArcButton;
|
|
|
|
private var _statisticsButton:ArcButton;
|
|
|
|
private var _closeButton:ArcButton;
|
|
|
|
private var _backButton:ArcButton;
|
|
|
|
private var _optionsButton:ArcButton;
|
|
|
|
public var options:OptionsMenu;
|
|
|
|
public var inOptions:Boolean = false;
|
|
|
|
public var confirmation:ConfirmationMenu;
|
|
|
|
public var inConfirmation:Boolean = false;
|
|
|
|
public function Menu()
|
|
{
|
|
var pane:MenuPane = null;
|
|
this.spriteCharacterButton = Menu_spriteCharacterButton;
|
|
this.spriteStatisticsButton = Menu_spriteStatisticsButton;
|
|
this._paneCharacter = new CharacterPane();
|
|
this._paneStatistics = new StatisticsPane();
|
|
this._paneMessageLog = new MessageLogPane();
|
|
this._buttons = new ArcButtonGroup();
|
|
super();
|
|
this._pane = this._paneCharacter;
|
|
for each(pane in [this._paneCharacter,this._paneStatistics])
|
|
{
|
|
pane.update();
|
|
}
|
|
add(this._buttons);
|
|
this._buttons.addButton(this._characterButton = new ArcButton(52,219,128,17,this.spriteCharacterButton).callback(function():void
|
|
{
|
|
_pane = _paneCharacter;
|
|
_pane.sync();
|
|
}).select());
|
|
this._buttons.addButton(this._statisticsButton = new ArcButton(52 + 127,219,128,17,this.spriteStatisticsButton).callback(function():void
|
|
{
|
|
_pane = _paneStatistics;
|
|
_pane.sync();
|
|
}));
|
|
this._optionsButton = new ArcButton(313,204,34,29,optionsButton).selectable(false).callback(function():void
|
|
{
|
|
inOptions = true;
|
|
});
|
|
this.add(this._optionsButton);
|
|
this.options = new OptionsMenu(function():void
|
|
{
|
|
inOptions = false;
|
|
});
|
|
this._backButton = new ArcButton(13,207,33,23,backButton).selectable(false).callback(function():void
|
|
{
|
|
toMenu();
|
|
});
|
|
this.add(this._backButton);
|
|
this._closeButton = new ArcButton(318,5,32,11,closeButton).selectable(false).callback(function():void
|
|
{
|
|
Data.state.toggleMenu();
|
|
});
|
|
this.add(this._closeButton);
|
|
this.confirmation = new ConfirmationMenu(this);
|
|
this.setAlpha(false);
|
|
setAll("scrollFactor",new FlxPoint(0,0));
|
|
alpha = 0;
|
|
}
|
|
|
|
override public function update() : void
|
|
{
|
|
var _loc1_:Array = null;
|
|
var _loc2_:Array = null;
|
|
var _loc3_:int = 0;
|
|
var _loc4_:ArcButton = null;
|
|
var _loc5_:Array = null;
|
|
if(this.inOptions)
|
|
{
|
|
if(FlxG.keys.justPressed("ESCAPE"))
|
|
{
|
|
FlxG.keys.update();
|
|
this.inOptions = false;
|
|
DataSerializer.save();
|
|
}
|
|
this.options.update();
|
|
_loc1_ = [this.options.mouse,this.options.kb1,this.options.kb2,this.options.reset];
|
|
_loc2_ = [["Mouse Controls","Use A/D or LEFT/RIGHT to move, W or SPACE or UP to jump, MOUSE to aim, MOUSE BUTTON to shoot."],["Keyboard Controls","Use A/D to move, W or SPACE to jump, ARROWS to aim and shoot."],["Inverse Keyboard","Use LEFT/RIGHT to move, UP or SPACE to jump, A/S/D/W to aim and shoot."],["Reset All Data","This will clear all your saved data and restart you from scratch. Hold shift and click this button to clear data."]];
|
|
_loc3_ = 0;
|
|
while(_loc3_ < _loc1_.length)
|
|
{
|
|
_loc4_ = _loc1_[_loc3_] as ArcButton;
|
|
_loc5_ = _loc2_[_loc3_] as Array;
|
|
if(_loc4_.hover())
|
|
{
|
|
if(tooltip == null || tooltip.source != _loc4_)
|
|
{
|
|
tooltip = new MenuTooltip(_loc4_.x + _loc4_.width / 2,_loc4_.y,_loc5_[0],_loc5_[1]);
|
|
tooltip.source = _loc4_;
|
|
}
|
|
hovering = true;
|
|
}
|
|
_loc3_++;
|
|
}
|
|
if(!hovering && tooltip != null)
|
|
{
|
|
tooltip = null;
|
|
}
|
|
hovering = false;
|
|
return;
|
|
}
|
|
if(this.inConfirmation)
|
|
{
|
|
this.confirmation.update();
|
|
return;
|
|
}
|
|
if(this._fading)
|
|
{
|
|
if(this._open)
|
|
{
|
|
_alpha += FlxG.elapsed * FADE_SPEED;
|
|
if(_alpha >= 1)
|
|
{
|
|
_alpha = 1;
|
|
this._fading = false;
|
|
Data.state.setMenu(this._open);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_alpha -= FlxG.elapsed * FADE_SPEED;
|
|
if(_alpha <= 0)
|
|
{
|
|
_alpha = 0;
|
|
this._fading = false;
|
|
Data.state.setMenu(this._open);
|
|
}
|
|
}
|
|
this.setAlpha();
|
|
}
|
|
if(this._pane == this._paneMessageLog)
|
|
{
|
|
this._statisticsButton.visible = this._characterButton.visible = this._optionsButton.visible = this._backButton.visible = false;
|
|
}
|
|
else
|
|
{
|
|
this._statisticsButton.visible = this._characterButton.visible = this._optionsButton.visible = this._backButton.visible = true;
|
|
}
|
|
this._pane.update();
|
|
super.update();
|
|
if(!hovering && tooltip != null)
|
|
{
|
|
tooltip = null;
|
|
}
|
|
hovering = false;
|
|
}
|
|
|
|
public function toMenu() : void
|
|
{
|
|
this.inConfirmation = true;
|
|
}
|
|
|
|
public function sync(param1:Boolean = false) : void
|
|
{
|
|
}
|
|
|
|
override public function draw() : void
|
|
{
|
|
this._pane.draw();
|
|
super.draw();
|
|
if(this.inOptions)
|
|
{
|
|
this.options.draw();
|
|
if(tooltip != null)
|
|
{
|
|
tooltip.draw();
|
|
}
|
|
return;
|
|
}
|
|
if(this.inConfirmation)
|
|
{
|
|
this.confirmation.draw();
|
|
return;
|
|
}
|
|
if(tooltip != null)
|
|
{
|
|
tooltip.draw();
|
|
}
|
|
}
|
|
|
|
public function fade(param1:Boolean, param2:int = 0) : void
|
|
{
|
|
this._fading = true;
|
|
this._open = param1;
|
|
if(param1)
|
|
{
|
|
if(param2 == 1)
|
|
{
|
|
this._characterButton.select(true,true);
|
|
this.setAlpha();
|
|
this._paneStatistics.alpha = 1;
|
|
this._paneStatistics.sync();
|
|
}
|
|
else if(param2 == 2)
|
|
{
|
|
this._statisticsButton.select(true,true);
|
|
this.setAlpha();
|
|
this._paneCharacter.alpha = 1;
|
|
this._paneCharacter.sync();
|
|
}
|
|
else if(param2 == 3)
|
|
{
|
|
this._pane = this._paneMessageLog;
|
|
this._pane.sync();
|
|
this.setAlpha();
|
|
}
|
|
else if(this._pane == this._paneMessageLog)
|
|
{
|
|
this._characterButton.select(true,true);
|
|
this.setAlpha();
|
|
this._paneStatistics.alpha = 1;
|
|
this._paneStatistics.sync();
|
|
}
|
|
else
|
|
{
|
|
this._pane.sync();
|
|
}
|
|
Data.state.setMenu(this._open);
|
|
}
|
|
}
|
|
|
|
private function setAlpha(param1:Boolean = true) : void
|
|
{
|
|
alpha = _alpha;
|
|
this._pane.alpha = _alpha;
|
|
var _loc2_:UI = Data.state.ui;
|
|
if(_loc2_ != null && param1)
|
|
{
|
|
Data.state.ui.alpha = 1 - _alpha;
|
|
}
|
|
}
|
|
|
|
public function getAlpha() : Number
|
|
{
|
|
return _alpha;
|
|
}
|
|
}
|
|
}
|
|
|