PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/game/dota_addons/spell_shop_ui/src SpellShopUI/tmpTest.as

https://github.com/eeSPee/SpellShop_UI
ActionScript | 406 lines | 269 code | 67 blank | 70 comment | 27 complexity | 81d547526582b2b31e6638510580317c MD5 | raw file
  1. package {
  2. //import the events
  3. import flash.events.MouseEvent;
  4. import flash.events.EventDispatcher;
  5. import flash.events.Event;
  6. //import display thingies so we can customize our button
  7. import flash.display.MovieClip;
  8. import flash.display.Sprite;
  9. import flash.display.Bitmap;
  10. import flash.display.BitmapData;
  11. import flash.display.SimpleButton;
  12. import flash.text.TextField;
  13. import flash.display.Graphics;
  14. //import the custom event class
  15. import ev_Invoke;
  16. import flash.geom.Point;
  17. import flash.text.TextFormat;
  18. import flash.display.Shape;
  19. import flash.text.AntiAliasType;
  20. public class tmpTest extends MovieClip {
  21. var _ID:String;
  22. var _nameLUA:String;
  23. var _texture:String;
  24. var _upState:Sprite = new Sprite;
  25. var _overState:Sprite = new Sprite;
  26. var _downState:Sprite = new Sprite;
  27. var _disabledState:Sprite = new Sprite;
  28. var _ownedState:Sprite = new Sprite;
  29. var _upgState:Sprite = new Sprite;
  30. var _isOwned:Boolean = false;
  31. var _isSellable:Boolean = true;
  32. var _isEnabled:Boolean = true;
  33. var _cost:int;
  34. var _size:Number;
  35. var _txtCost:TextField;
  36. var _txtPnt:TextField;
  37. var _sellFactor:Number;
  38. var _upgFactor:Number;
  39. var _curLvl:int;
  40. var _maxLvl:int;
  41. var _isUpg:Boolean;
  42. var _pntCost:int;
  43. var _pntSellFac:Number;
  44. var _pntIncrement:int;
  45. var _pntIncLvl:int;
  46. var _useRes:Boolean;
  47. var _useGold:Boolean;
  48. //hold the gameAPI
  49. var gameAPI:Object;
  50. var globals:Object;
  51. public function tmpTest() {
  52. }
  53. public function remListeners() {
  54. this.removeEventListener(MouseEvent.CLICK, onBtnClick);
  55. this.removeEventListener(MouseEvent.MOUSE_DOWN, mouse_down);
  56. this.removeEventListener(MouseEvent.MOUSE_UP, mouse_up);
  57. }
  58. public function addListeners() {
  59. this.addEventListener(MouseEvent.CLICK, onBtnClick);
  60. this.addEventListener(MouseEvent.MOUSE_DOWN, mouse_down);
  61. this.addEventListener(MouseEvent.MOUSE_UP, mouse_up);
  62. }
  63. public function show_owned ( arg:Boolean ) {
  64. if( arg ) {
  65. _ownedState.visible = true;
  66. set_enabled(false, true);
  67. } else {
  68. _ownedState.visible = false;
  69. set_enabled(true, true);
  70. }
  71. }
  72. public function set_enabled( arg:Boolean, arg2:Boolean ) {
  73. if( arg ) {
  74. _isEnabled = true;
  75. _disabledState.visible = false;
  76. addListeners();
  77. } else {
  78. _isEnabled = false;
  79. // if we're calling from show_owned, dont change the _disabledState
  80. if( !arg2 ) _disabledState.visible = true;
  81. remListeners();
  82. }
  83. }
  84. public function mouse_out( e:MouseEvent ) {
  85. //trace("mouse out");
  86. if( _isEnabled ) set_visibility(true, false, false);
  87. this.globals.Loader_rad_mode_panel.gameAPI.OnHideAbilityTooltip();
  88. }
  89. public function mouse_over( e:MouseEvent ) {
  90. //trace("mouse over");
  91. if( _isEnabled ) {
  92. //change visibility of the ability button
  93. set_visibility(false, true, false);
  94. }
  95. //trace('[mouse_over] ' + this._nameLUA);
  96. //set the object
  97. var ob:Object = e.target;
  98. // set the point because fuck
  99. var lp:Point = ob.localToGlobal(new Point(0, 0));
  100. this.globals.Loader_rad_mode_panel.gameAPI.OnShowAbilityTooltip(lp.x+_size, lp.y+(_size/5), ob._nameLUA);
  101. }
  102. public function mouse_down( e:MouseEvent ) {
  103. //trace("mouse down");
  104. if( _isEnabled ) set_visibility(false, false, true);
  105. }
  106. public function mouse_up( e:MouseEvent ) {
  107. //trace("mouse up");
  108. if( _isEnabled ) set_visibility(false, true, false);
  109. }
  110. // sets different visibilities for different states (hover, click, default..)
  111. public function set_visibility(v1:Boolean, v2:Boolean, v3:Boolean) {
  112. _upState.visible = v1;
  113. _overState.visible = v2;
  114. _downState.visible = v3;
  115. }
  116. public function set_text( amount : Number) {
  117. var txFormat:TextFormat = new TextFormat();
  118. amount = Math.floor(amount);
  119. txFormat.color = 0xFFFFFF;
  120. txFormat.size = this._size/4;
  121. txFormat.font = "$TextFont";
  122. txFormat.align = "center";
  123. txFormat.rightMargin = 2;
  124. _txtCost.multiline = false;
  125. _txtCost.wordWrap = false;
  126. _txtCost.background = false;
  127. _txtCost.autoSize = "left";
  128. _txtPnt.antiAliasType = AntiAliasType.ADVANCED;
  129. //_txtCost.border = true;
  130. //_txtCost.borderColor = 0xFFFFFF;
  131. _txtCost.background = true;
  132. _txtCost.backgroundColor = 0x000000;
  133. _txtCost.text = amount.toString();
  134. _txtCost.setTextFormat(txFormat);
  135. _txtCost.selectable = false;
  136. _txtCost.x = _size-_txtCost.width;
  137. _txtCost.y = _size-_txtCost.height;
  138. }
  139. public function set_pnt( amount : Number) {
  140. var txFormat:TextFormat = new TextFormat();
  141. amount = Math.floor(amount);
  142. txFormat.color = 0xFFFFFF;
  143. txFormat.size = this._size/4;
  144. txFormat.font = "$TextFont";
  145. txFormat.align = "center";
  146. txFormat.leftMargin = 2;
  147. _txtPnt.multiline = false;
  148. _txtPnt.wordWrap = false;
  149. _txtPnt.background = false;
  150. _txtPnt.autoSize = "left";
  151. _txtPnt.antiAliasType = AntiAliasType.ADVANCED;
  152. //_txtPnt.border = true;
  153. //_txtPnt.borderColor = 0xFFFFFF;
  154. _txtPnt.background = true;
  155. _txtPnt.backgroundColor = 0x000000;
  156. _txtPnt.text = amount.toString();
  157. _txtPnt.setTextFormat(txFormat);
  158. _txtPnt.selectable = false;
  159. _txtPnt.x = 0;
  160. _txtPnt.y = _size-_txtPnt.height;
  161. }
  162. public function setup_btn(args:Object, api:Object, globals:Object, size:int, useRes:Boolean, useGold:Boolean ) {
  163. this.gameAPI = api;
  164. this.globals = globals;
  165. this._useRes = useRes;
  166. this._useGold = useGold;
  167. // set up base spell info
  168. this._ID = args._ID;
  169. this._nameLUA = args._name;
  170. this._texture = args._texture;
  171. this._size = size;
  172. if( args._isSellable == "true" ) this._isSellable = true; else this._isSellable = false;
  173. if( args._isOwned == "true" ) this._isOwned = true; else this._isOwned = false;
  174. this._cost = args._cost;
  175. this._sellFactor = args._sellFactor;
  176. this._upgFactor = args._upgFactor;
  177. this._curLvl = args._curLvl;
  178. this._maxLvl = args._maxLvl;
  179. if( args._isUpg == "true" ) this._isUpg = true; else this._isUpg = false;
  180. this._pntCost = args._pntCost;
  181. this._pntSellFac = args._pntSellFac;
  182. this._pntIncrement = args._pntIncrement;
  183. this._pntIncLvl = args._pntIncLvl;
  184. // set the clip to act as a button, also set the children not to interact with the mouse as it screws the click
  185. this.buttonMode = true;
  186. this.mouseChildren = false;
  187. //set our icon used passed to us by LUA
  188. //var texture_icon:Class = getDefinitionByName(this._texture) as Class;
  189. //set the bitmaps for different states.. there's probably a better way to do this
  190. var bmpBuffUp:MovieClip = new MovieClip;
  191. var bmpBuffOver:MovieClip = new MovieClip;
  192. var bmpBuffDown:MovieClip = new MovieClip;
  193. var bmpBuffDisabled:MovieClip = new MovieClip;
  194. var bmpBuffOwned:MovieClip = new MovieClip;
  195. var bmpBuffUpg:MovieClip = new MovieClip;
  196. // load the images
  197. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffUp, false);
  198. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffOver, false);
  199. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffDown, false);
  200. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffDisabled, false);
  201. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffOwned, false);
  202. this.globals.LoadImage("images/spellicons/" + this._texture + ".png", bmpBuffUpg, false);
  203. //trace("[LoadAbilityImage] "+this._texture + " visibility:" + bmpBuffUp.visible);
  204. //trace("[LoadAbilityImage] "+this._texture + " height:" + bmpBuffUp.height);
  205. //trace("[LoadAbilityImage] "+this._texture + " width:" + bmpBuffUp.width);
  206. //set the bitmap widths.. gonna make this scaleable later
  207. /*bmpBuffUp.width = bmpBuffUp.height = _size;
  208. bmpBuffOver.width = bmpBuffOver.height = _size;
  209. bmpBuffDown.width = bmpBuffDown.height = _size;
  210. bmpBuffDisabled.width = bmpBuffDisabled.height = _size;
  211. bmpBuffOwned.width = bmpBuffOwned.height = _size;*/
  212. //prepare the states
  213. _upState.addChild(bmpBuffUp);
  214. _upState.addChild(new btnTemp_up);
  215. _overState.addChild(bmpBuffOver);
  216. _overState.addChild(new btnTemp_over);
  217. _downState.addChild(bmpBuffDown);
  218. _downState.addChild(new btnTemp_down);
  219. _disabledState.addChild(bmpBuffDisabled);
  220. _disabledState.addChild(new btnTemp_disabled);
  221. _ownedState.addChild(bmpBuffOwned);
  222. _ownedState.addChild(new btnTemp_owned);
  223. //_upgState.addChild(bmpBuffUpg);
  224. _upgState.addChild(new btnTemp_upg);
  225. _upState.width = _upState.height = _size;
  226. _overState.width = _overState.height = _size;
  227. _downState.width = _downState.height = _size;
  228. _disabledState.width = _disabledState.height = _size;
  229. _ownedState.width = _ownedState.height = _size;
  230. _upgState.width = _upgState.height = _size;
  231. _ownedState.visible = false;
  232. _upgState.visible = false;
  233. // --------------------------------------
  234. // set the textfield for showing goldcost
  235. // --------------------------------------
  236. _txtCost = new TextField;
  237. var txFormat:TextFormat = new TextFormat();
  238. txFormat.color = 0xFFFFFF;
  239. txFormat.size = this._size/4;
  240. txFormat.font = "$TextFont";
  241. txFormat.align = "center";
  242. txFormat.rightMargin = 2;
  243. _txtCost.multiline = false;
  244. _txtCost.wordWrap = false;
  245. _txtCost.background = false;
  246. _txtCost.autoSize = "left";
  247. _txtCost.antiAliasType = AntiAliasType.ADVANCED;
  248. //_txtCost.border = true;
  249. //_txtCost.borderColor = 0xFFFFFF;
  250. _txtCost.background = true;
  251. _txtCost.backgroundColor = 0x000000;
  252. _txtCost.text = this._cost.toString();
  253. _txtCost.setTextFormat(txFormat);
  254. _txtCost.selectable = false;
  255. //_txtCost.alpha = 1;
  256. /*var txtShape:Shape = new Shape;
  257. txtShape.graphics.beginFill(0xFFCC00, 0.6);
  258. txtShape.graphics.drawRect(0,0,_txtCost.textWidth,_txtCost.textHeight);
  259. txtShape.graphics.endFill();*/
  260. // -------------------------------------
  261. // set the textfield for showing pntcost
  262. // -------------------------------------
  263. _txtPnt = new TextField;
  264. var txPntFormat:TextFormat = new TextFormat();
  265. txPntFormat.color = 0xFFFFFF;
  266. txPntFormat.size = this._size/4;
  267. txPntFormat.font = "$TextFont";
  268. txPntFormat.align = "center";
  269. txPntFormat.leftMargin = 2;
  270. _txtPnt.multiline = false;
  271. _txtPnt.wordWrap = false;
  272. _txtPnt.background = false;
  273. _txtPnt.autoSize = "left";
  274. _txtPnt.antiAliasType = AntiAliasType.ADVANCED;
  275. //_txtPnt.border = true;
  276. //_txtPnt.borderColor = 0xFFFFFF;
  277. _txtPnt.background = true;
  278. _txtPnt.backgroundColor = 0x000000;
  279. _txtPnt.text = this._pntCost.toString();
  280. _txtPnt.setTextFormat(txPntFormat);
  281. _txtPnt.selectable = false;
  282. //_txtPnt.alpha = 1;
  283. /*var pntShape:Shape = new Shape;
  284. pntShape.graphics.beginFill(0xFFCC00, 0.6);
  285. pntShape.graphics.drawRect(0,0,_txtPnt.textWidth,_txtPnt.textHeight);
  286. pntShape.graphics.endFill();*/
  287. //add the states to the button
  288. this.addChild(this._upState);
  289. this.addChild(this._overState);
  290. this.addChild(this._downState);
  291. this.addChild(this._disabledState);
  292. this.addChild(this._ownedState);
  293. this.addChild(this._upgState);
  294. //this.addChild(txtShape);
  295. this.addChild(_txtCost);
  296. //this.addChild(pntShape);
  297. this.addChild(_txtPnt);
  298. _txtCost.x = _size-_txtCost.width;
  299. _txtCost.y = _size-_txtCost.height;
  300. //txtShape.x = _txtCost.x;
  301. //txtShape.y = _txtCost.y;
  302. _txtPnt.x = 0;
  303. _txtPnt.y = _size-_txtPnt.height;
  304. //pntShape.x = _txtPnt.x;
  305. //pntShape.y = _txtPnt.y;
  306. if( this._ID == "0000" || !_useRes ) {
  307. _txtPnt.visible = false;
  308. //pntShape.visible = false;
  309. }
  310. if( this._ID != "0000" && !_useGold ) {
  311. _txtCost.visible = false;
  312. }
  313. //move the downstate a bit so it looks pressed
  314. this._downState.x+=1;
  315. this._downState.y+=1;
  316. bmpBuffDown.x+=1;
  317. bmpBuffDown.y+=1;
  318. // at last, set the visibility to the default state
  319. set_visibility(true, false, false);
  320. this.addEventListener(MouseEvent.ROLL_OVER, mouse_over);
  321. this.addEventListener(MouseEvent.ROLL_OUT, mouse_out);
  322. }
  323. public function onBtnClick( e:MouseEvent ) {
  324. if( _isEnabled ) {
  325. // initialize custom event
  326. var evt:ev_Invoke = new ev_Invoke(ev_Invoke.INVOKE);
  327. // add the spell ID to the event so it gets passed
  328. evt._spell_ID = this._ID;
  329. // check if it is owned
  330. if( _isOwned ) evt._owned = true; else evt._owned = false;
  331. // hide the tooltip
  332. this.globals.Loader_rad_mode_panel.gameAPI.OnHideAbilityTooltip();
  333. set_visibility(true,false,false);
  334. // send the event that the parent class is listening to
  335. dispatchEvent(evt);
  336. }
  337. }
  338. }
  339. }