1 decade ago by TigerJ
I am attempting my first plugin for a semi dynamic menu
I have this method defined below:
here is an example of it being called:
I had planned on the following to establish each items event/action during the update inside my plugin file.
What I am noticing however is that the first menu item properly functions, and any other item does not behave as planned (the additional items added replicate the first items inputAction and inputEvent.
Any advice would be great. I've written tons of javascript but this is my first plugin attempt. :)
You can view a baked version of this in action here: http://devbriggs.com/experiment/index.html
(open console click polaris or violett. both perform the inputEvent for polaris)
I have this method defined below:
addItem: function(menutext, menulabel, inputAction,inputEvent){ var item=new Object; item.text = menutext; item.label = menulabel; item.inputAction = inputAction; item.inputEvent = inputEvent; this.MenuItems.push( item ); },
here is an example of it being called:
this.myMenu.addItem("polaris","cat","shoot",{ action: function(){ console.log("black cat"); } });
I had planned on the following to establish each items event/action during the update inside my plugin file.
for(i=0;i<this.MenuItems.length;i++) { //establish bounds var leftBounds = this.MenuStart.x+((this.ButtonSize.x+this.Spacing.x)*(i)); var rightBounds = this.MenuStart.x+((this.ButtonSize.x+this.Spacing.x)*(i))+this.ButtonSize.x; var upperBounds = this.MenuStart.y+((this.ButtonSize.y+this.Spacing.y)*(i)); var lowerBounds = this.MenuStart.y+((this.ButtonSize.y+this.Spacing.y)*(i))+this.ButtonSize.y; //listen for specified input event actions and if actions while in bounds run functions if(ig.input.mouse.x>leftBounds&&ig.input.mouse.x<rightBounds&&ig.input.mouse.y>upperBounds&&ig.input.mouse.y<lowerBounds) { if(ig.input.pressed(this.MenuItems[i].inputAction)) { this.MenuItems[i].inputEvent.action(); } } }
What I am noticing however is that the first menu item properly functions, and any other item does not behave as planned (the additional items added replicate the first items inputAction and inputEvent.
Any advice would be great. I've written tons of javascript but this is my first plugin attempt. :)
You can view a baked version of this in action here: http://devbriggs.com/experiment/index.html
(open console click polaris or violett. both perform the inputEvent for polaris)