|
@@ -1,18 +1,23 @@
|
|
class Pad extends hxd.App {
|
|
class Pad extends hxd.App {
|
|
-
|
|
|
|
|
|
+
|
|
var flow : h2d.Flow;
|
|
var flow : h2d.Flow;
|
|
var l : Array<PadUI>;
|
|
var l : Array<PadUI>;
|
|
|
|
+ var tf : h2d.Text;
|
|
|
|
|
|
override function init() {
|
|
override function init() {
|
|
l = [];
|
|
l = [];
|
|
flow = new h2d.Flow(s2d);
|
|
flow = new h2d.Flow(s2d);
|
|
flow.padding = 20;
|
|
flow.padding = 20;
|
|
flow.isVertical = true;
|
|
flow.isVertical = true;
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ tf = new h2d.Text(hxd.res.DefaultFont.get(), flow);
|
|
|
|
+ tf.text = "Waiting for pad...";
|
|
|
|
+
|
|
hxd.Pad.wait(onPad);
|
|
hxd.Pad.wait(onPad);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
function onPad( p : hxd.Pad ){
|
|
function onPad( p : hxd.Pad ){
|
|
|
|
+ tf.remove();
|
|
var ui = new PadUI(p, flow);
|
|
var ui = new PadUI(p, flow);
|
|
l.push( ui );
|
|
l.push( ui );
|
|
p.onDisconnect = function(){
|
|
p.onDisconnect = function(){
|
|
@@ -40,26 +45,26 @@ class Pad extends hxd.App {
|
|
}
|
|
}
|
|
|
|
|
|
class PadUI extends h2d.Sprite {
|
|
class PadUI extends h2d.Sprite {
|
|
-
|
|
|
|
|
|
+
|
|
var tfName : h2d.Text;
|
|
var tfName : h2d.Text;
|
|
-
|
|
|
|
|
|
+
|
|
var bg : h2d.Graphics;
|
|
var bg : h2d.Graphics;
|
|
var main : h2d.Graphics;
|
|
var main : h2d.Graphics;
|
|
var left : h2d.Graphics;
|
|
var left : h2d.Graphics;
|
|
var right : h2d.Graphics;
|
|
var right : h2d.Graphics;
|
|
-
|
|
|
|
|
|
+
|
|
var lt : h2d.Graphics;
|
|
var lt : h2d.Graphics;
|
|
var rt : h2d.Graphics;
|
|
var rt : h2d.Graphics;
|
|
-
|
|
|
|
|
|
+
|
|
var buttons : Map<String,h2d.Text>;
|
|
var buttons : Map<String,h2d.Text>;
|
|
-
|
|
|
|
|
|
+
|
|
var pad : hxd.Pad;
|
|
var pad : hxd.Pad;
|
|
-
|
|
|
|
|
|
+
|
|
public function new( p : hxd.Pad, parent : h2d.Sprite ){
|
|
public function new( p : hxd.Pad, parent : h2d.Sprite ){
|
|
super( parent );
|
|
super( parent );
|
|
-
|
|
|
|
|
|
+
|
|
pad = p;
|
|
pad = p;
|
|
-
|
|
|
|
|
|
+
|
|
bg = new h2d.Graphics(this);
|
|
bg = new h2d.Graphics(this);
|
|
bg.lineStyle(1,0xFFFFFF,0.5);
|
|
bg.lineStyle(1,0xFFFFFF,0.5);
|
|
bg.drawRect(0,0,600,160);
|
|
bg.drawRect(0,0,600,160);
|
|
@@ -69,26 +74,26 @@ class PadUI extends h2d.Sprite {
|
|
bg.drawRect(260,20,20,100);
|
|
bg.drawRect(260,20,20,100);
|
|
bg.drawRect(300,20,20,100);
|
|
bg.drawRect(300,20,20,100);
|
|
bg.endFill();
|
|
bg.endFill();
|
|
-
|
|
|
|
|
|
+
|
|
var fnt = hxd.Res.customFont.toFont();
|
|
var fnt = hxd.Res.customFont.toFont();
|
|
-
|
|
|
|
|
|
+
|
|
tfName = new h2d.Text(fnt,this);
|
|
tfName = new h2d.Text(fnt,this);
|
|
tfName.text = pad.name;
|
|
tfName.text = pad.name;
|
|
-
|
|
|
|
|
|
+
|
|
main = new h2d.Graphics(this);
|
|
main = new h2d.Graphics(this);
|
|
main.lineStyle(1,0x00FF00,1);
|
|
main.lineStyle(1,0x00FF00,1);
|
|
main.drawCircle(0,0,4);
|
|
main.drawCircle(0,0,4);
|
|
main.endFill();
|
|
main.endFill();
|
|
-
|
|
|
|
|
|
+
|
|
left = new h2d.Graphics(this);
|
|
left = new h2d.Graphics(this);
|
|
right = new h2d.Graphics(this);
|
|
right = new h2d.Graphics(this);
|
|
-
|
|
|
|
|
|
+
|
|
for( g in [left,right] ){
|
|
for( g in [left,right] ){
|
|
g.beginFill(0xFF0000);
|
|
g.beginFill(0xFF0000);
|
|
g.drawCircle(0,0,2);
|
|
g.drawCircle(0,0,2);
|
|
g.endFill();
|
|
g.endFill();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
lt = new h2d.Graphics(this);
|
|
lt = new h2d.Graphics(this);
|
|
lt.x = 260;
|
|
lt.x = 260;
|
|
rt = new h2d.Graphics(this);
|
|
rt = new h2d.Graphics(this);
|
|
@@ -100,9 +105,9 @@ class PadUI extends h2d.Sprite {
|
|
g.scaleY = 0;
|
|
g.scaleY = 0;
|
|
g.y = 120;
|
|
g.y = 120;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
buttons = new Map();
|
|
buttons = new Map();
|
|
-
|
|
|
|
|
|
+
|
|
var x = 0;
|
|
var x = 0;
|
|
for( n in ["A","B","X","Y","LB","RB","back","start","dpadUp","dpadDown","dpadLeft","dpadRight"] ){
|
|
for( n in ["A","B","X","Y","LB","RB","back","start","dpadUp","dpadDown","dpadLeft","dpadRight"] ){
|
|
var t = new h2d.Text(fnt,this);
|
|
var t = new h2d.Text(fnt,this);
|
|
@@ -115,23 +120,23 @@ class PadUI extends h2d.Sprite {
|
|
x += t.textWidth;
|
|
x += t.textWidth;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function update(){
|
|
public function update(){
|
|
var conf = #if flash hxd.Pad.CONFIG_XBOX #else hxd.Pad.CONFIG_SDL #end;
|
|
var conf = #if flash hxd.Pad.CONFIG_XBOX #else hxd.Pad.CONFIG_SDL #end;
|
|
main.x = 20 + 50 + pad.xAxis * 50;
|
|
main.x = 20 + 50 + pad.xAxis * 50;
|
|
main.y = 20 + 50 + pad.yAxis * 50;
|
|
main.y = 20 + 50 + pad.yAxis * 50;
|
|
-
|
|
|
|
|
|
+
|
|
left.x = 20 + 50 + pad.values[ conf.analogX ] * 50;
|
|
left.x = 20 + 50 + pad.values[ conf.analogX ] * 50;
|
|
left.y = 20 + 50 - pad.values[ conf.analogY ] * 50;
|
|
left.y = 20 + 50 - pad.values[ conf.analogY ] * 50;
|
|
left.setScale( 1 + 3 * pad.values[conf.analogClick] );
|
|
left.setScale( 1 + 3 * pad.values[conf.analogClick] );
|
|
-
|
|
|
|
|
|
+
|
|
right.x = 140 + 50 + pad.values[ conf.ranalogX ] * 50;
|
|
right.x = 140 + 50 + pad.values[ conf.ranalogX ] * 50;
|
|
right.y = 20 + 50 - pad.values[ conf.ranalogY ] * 50;
|
|
right.y = 20 + 50 - pad.values[ conf.ranalogY ] * 50;
|
|
right.setScale( 1 + 3 * pad.values[conf.ranalogClick] );
|
|
right.setScale( 1 + 3 * pad.values[conf.ranalogClick] );
|
|
-
|
|
|
|
|
|
+
|
|
lt.scaleY = -pad.values[ conf.LT ];
|
|
lt.scaleY = -pad.values[ conf.LT ];
|
|
rt.scaleY = -pad.values[ conf.RT ];
|
|
rt.scaleY = -pad.values[ conf.RT ];
|
|
-
|
|
|
|
|
|
+
|
|
for( k in buttons.keys() )
|
|
for( k in buttons.keys() )
|
|
buttons[k].alpha = 0.3 + (pad.buttons[ Reflect.field(conf,k) ] ? 0.7 : 0);
|
|
buttons[k].alpha = 0.3 + (pad.buttons[ Reflect.field(conf,k) ] ? 0.7 : 0);
|
|
}
|
|
}
|