| 1 | package
|
|---|
| 2 | {
|
|---|
| 3 | public class ClickablePool
|
|---|
| 4 | {
|
|---|
| 5 | public var clist:Array;
|
|---|
| 6 | public var count:int;
|
|---|
| 7 |
|
|---|
| 8 | public var none_enable:Boolean;
|
|---|
| 9 | public var selected:String;
|
|---|
| 10 |
|
|---|
| 11 | public static const MAX_COUNT:int = 32;
|
|---|
| 12 |
|
|---|
| 13 | public function ClickablePool(none_enable:Boolean = true){
|
|---|
| 14 | clist = new Array();
|
|---|
| 15 |
|
|---|
| 16 | this.count = count;
|
|---|
| 17 | this.selected = "";
|
|---|
| 18 | this.none_enable = none_enable;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | public function add(str:String,pos:Vec3, arg:*):void
|
|---|
| 22 | {
|
|---|
| 23 | if(arg is Vec3)
|
|---|
| 24 | {
|
|---|
| 25 | clist.push(new Clickable(str,pos,arg));
|
|---|
| 26 | }
|
|---|
| 27 | else
|
|---|
| 28 | {
|
|---|
| 29 | var imgb:ImageButton = new ImageButton(arg);
|
|---|
| 30 | var size:Vec3 = new Vec3(imgb.getWidth(), imgb.getHeight() , 0);
|
|---|
| 31 | var newc:Clickable = new Clickable(str , pos , size , 0 , imgb);
|
|---|
| 32 |
|
|---|
| 33 | for(var i:int = 0; i < MAX_COUNT; i++){
|
|---|
| 34 | if(!clist[i]){
|
|---|
| 35 | clist[i] = newc;
|
|---|
| 36 | if(selected == "" && none_enable == false) selected = str;
|
|---|
| 37 | return;
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public function getMouseOver():String{
|
|---|
| 44 | for each(var c:Clickable in clist){
|
|---|
| 45 | if(c != null && c.onMouse()){
|
|---|
| 46 | return c.str;
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 | return "";
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | public function getMouseClick():String{
|
|---|
| 53 | if(Hell.isPushMouse()) {
|
|---|
| 54 | var mov:String = getMouseOver();
|
|---|
| 55 | if(mov != ""){
|
|---|
| 56 | if(selected == mov && none_enable == true){
|
|---|
| 57 | selected = "";
|
|---|
| 58 | }else{
|
|---|
| 59 | selected = mov;
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | return mov;
|
|---|
| 63 | }
|
|---|
| 64 | return "";
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | public function getSelected():String{return selected;}
|
|---|
| 68 |
|
|---|
| 69 | public function draw():void
|
|---|
| 70 | {
|
|---|
| 71 | for each(var c:Clickable in clist){
|
|---|
| 72 | if(c){
|
|---|
| 73 | if(c.str == selected){
|
|---|
| 74 | c.selected = true;
|
|---|
| 75 | }else{
|
|---|
| 76 | c.selected = false;
|
|---|
| 77 | }
|
|---|
| 78 | c.draw();
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | class Clickable{
|
|---|
| 86 | public var position:Vec3;
|
|---|
| 87 | public var size:Vec3;
|
|---|
| 88 | public var str:String;
|
|---|
| 89 | public var zoom:Number;
|
|---|
| 90 | public var selected:Boolean;
|
|---|
| 91 |
|
|---|
| 92 | public var imagebutton:ImageButton;
|
|---|
| 93 |
|
|---|
| 94 | public function Clickable(str:String,pos:Vec3,size:Vec3,zoom:Number = 2.0,imagebutton:ImageButton = null){
|
|---|
| 95 | this.str = str;
|
|---|
| 96 | this.position = pos;
|
|---|
| 97 | this.size = size;
|
|---|
| 98 | this.zoom = zoom;
|
|---|
| 99 | this.imagebutton = imagebutton;
|
|---|
| 100 | this.selected = false;
|
|---|
| 101 |
|
|---|
| 102 | if(imagebutton){
|
|---|
| 103 | imagebutton.setPosition(pos);
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | public function onMouse():Boolean{
|
|---|
| 108 | if(position.x <= Hell.getMouseX() && position.x + size.x >= Hell.getMouseX()
|
|---|
| 109 | && position.y <= Hell.getMouseY() && position.y + size.y >= Hell.getMouseY())
|
|---|
| 110 | {
|
|---|
| 111 | return true;
|
|---|
| 112 | }
|
|---|
| 113 | return false;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | public function draw():void{
|
|---|
| 117 | if(imagebutton is ImageButton == false){
|
|---|
| 118 | // 通常
|
|---|
| 119 | if(onMouse()){
|
|---|
| 120 | Hell.drawFont(str , position.x , position.y/* , zoom , 255,128,32*/);
|
|---|
| 121 | }else{
|
|---|
| 122 | Hell.drawFont(str , position.x , position.y/* , zoom , 64, 64, 64*/);
|
|---|
| 123 | }
|
|---|
| 124 | }else{
|
|---|
| 125 | imagebutton.draw(selected , onMouse());
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 | } |
|---|