PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/MonsterMenu.hx

http://portable-monsters.googlecode.com/
Haxe | 933 lines | 793 code | 108 blank | 32 comment | 82 complexity | 8e762ba40e534106e77a1ea463f4b428 MD5 | raw file
  1. import flash.events.Event;
  2. import flash.display.Sprite;
  3. import flash.events.MouseEvent;
  4. import flash.display.BitmapData;
  5. import flash.display.Bitmap;
  6. import flash.geom.Matrix;
  7. import flash.geom.Rectangle;
  8. import flash.geom.Point;
  9. import flash.text.TextField;
  10. import flash.text.TextFieldAutoSize;
  11. import flash.text.TextFormat;
  12. import flash.text.TextFormatAlign;
  13. import MonsterButton;
  14. import Images;
  15. class MonsterMenuEvent extends Event{
  16. public var ID:Int;
  17. public function new(customEventString:String,inID:Int){
  18. ID = inID;
  19. super(customEventString, true, false);
  20. }
  21. }
  22. class MonsterMenu extends Sprite
  23. {
  24. private var background:Sprite;
  25. public var CurrentState:String;
  26. public var MonsterCurrent:Sprite;
  27. public var Status:Sprite;
  28. public var StatusText:TextField;
  29. public var ItemConfirmBackground:Sprite;
  30. public var ItemYes:Sprite;
  31. public var ItemNo:Sprite;
  32. public var ItemConfirm:TextField;
  33. public var MonsterArchive:Sprite;
  34. public var currentTrainer:Trainer;
  35. public var currentMonsterInfo:Monster;
  36. public var currentMonster:Monster;
  37. public var currentMonsterArchive:Monster;
  38. public var PrevMonsterPage:Sprite;
  39. public var NextMonsterPage:Sprite;
  40. public var MonsterPage:Int;
  41. private var Text:TextField;
  42. private var table:Sprite;
  43. private var tableAdded:Bool;
  44. private var MonsterPic:CustomSprite;
  45. private var AttackMenu:Sprite;
  46. public var AttackPage:Int;
  47. public var PrevAttackPage:Sprite;
  48. public var NextAttackPage:Sprite;
  49. private var currentDesc:TextField;
  50. private var currentTitle:TextField;
  51. private var currentType:TextField;
  52. private var tableExit:Sprite;
  53. public var ExitMenu:Sprite;
  54. // public var volume:Bool;
  55. // public var sound:Bool;
  56. public function new(inTrainer:Trainer)
  57. {
  58. super();
  59. tableAdded = false;
  60. currentTrainer = inTrainer;
  61. CurrentState = "";
  62. //Resize Image
  63. background = new Sprite();
  64. background.graphics.lineStyle(1);
  65. background.graphics.beginFill(0xFFFFFF);
  66. background.graphics.drawRect(0, 0,640-150,Constants.flashHeight);
  67. background.graphics.endFill();
  68. background.x = 0 ; background.y = 0;
  69. //End Resize
  70. addChild(background);
  71. ExitMenu = new CustomSprite();
  72. ExitMenu.graphics.beginFill(0xFFFFFF);
  73. ExitMenu.graphics.lineStyle(1);
  74. ExitMenu.graphics.drawRect(0,0,25,25);
  75. ExitMenu.graphics.beginBitmapFill(new XButton());
  76. ExitMenu.graphics.drawRect(0, 0, 25, 25);
  77. ExitMenu.graphics.endFill();
  78. ExitMenu.x=background.width-35;
  79. ExitMenu.y = 10;
  80. ExitMenu.buttonMode = true;
  81. ExitMenu.addEventListener(MouseEvent.CLICK, onExitMenuClick);
  82. addChild(ExitMenu);
  83. Text = new TextField();
  84. PrevMonsterPage = new Sprite();
  85. var PrevMonsterPageText = new TextField();
  86. PrevMonsterPageText.htmlText = "<font size='14'>Prev</font>";
  87. //
  88. PrevMonsterPage.addChild(PrevMonsterPageText);
  89. PrevMonsterPageText.width = 70;
  90. PrevMonsterPageText.autoSize = TextFieldAutoSize.CENTER;
  91. PrevMonsterPageText.selectable = false;
  92. PrevMonsterPageText.mouseEnabled = false;
  93. PrevMonsterPage.buttonMode = true;
  94. PrevMonsterPage.addChild(PrevMonsterPageText);
  95. PrevMonsterPage.addEventListener(MouseEvent.CLICK, onPrevMonsterPageClick);
  96. PrevMonsterPage.graphics.beginFill(0xFFFFFF);
  97. PrevMonsterPage.graphics.lineStyle(1);
  98. PrevMonsterPage.graphics.drawRect(0,0,70,32);
  99. PrevMonsterPage.graphics.endFill();
  100. PrevMonsterPage.y = 512-45; PrevMonsterPage.x = 80;
  101. NextMonsterPage = new Sprite();
  102. var NextMonsterPageText = new TextField();
  103. NextMonsterPageText.htmlText = "<font size='14'>Next</font>";
  104. //
  105. NextMonsterPage.addChild(NextMonsterPageText);
  106. NextMonsterPageText.width = 70;
  107. NextMonsterPageText.autoSize = TextFieldAutoSize.CENTER;
  108. NextMonsterPageText.selectable = false;
  109. NextMonsterPageText.mouseEnabled = false;
  110. NextMonsterPage.buttonMode = true;
  111. NextMonsterPage.addChild(NextMonsterPageText);
  112. NextMonsterPage.addEventListener(MouseEvent.CLICK, onNextMonsterPageClick);
  113. NextMonsterPage.graphics.beginFill(0xFFFFFF);
  114. NextMonsterPage.graphics.lineStyle(1);
  115. NextMonsterPage.graphics.drawRect(0,0,70,32);
  116. NextMonsterPage.graphics.endFill();
  117. NextMonsterPage.y = 512-45;NextMonsterPage.x = 165;
  118. initMonsterArchive();
  119. initMonsterCurrent();
  120. MonsterPage = 1;
  121. AttackPage = 1;
  122. PrevAttackPage = new Sprite();
  123. var PrevAttackPageText = new TextField();
  124. PrevAttackPageText.htmlText = "<font size='14'>Prev</font>";
  125. //
  126. this.addChild(PrevAttackPageText);
  127. PrevAttackPageText.width = 70;
  128. PrevAttackPageText.autoSize = TextFieldAutoSize.CENTER;
  129. PrevAttackPageText.selectable = false;
  130. PrevAttackPageText.mouseEnabled = false;
  131. PrevAttackPage.buttonMode = true;
  132. PrevAttackPage.addChild(PrevAttackPageText);
  133. PrevAttackPage.addEventListener(MouseEvent.CLICK, onPrevAttackPageClick);
  134. PrevAttackPage.graphics.beginFill(0xFFFFFF);
  135. PrevAttackPage.graphics.lineStyle(1);
  136. PrevAttackPage.graphics.drawRect(0,0,70,32);
  137. PrevAttackPage.graphics.endFill();
  138. PrevAttackPage.y = 222-40; PrevAttackPage.x = 90;
  139. NextAttackPage = new Sprite();
  140. var NextAttackPageText = new TextField();
  141. NextAttackPageText.htmlText = "<font size='14'>Next</font>";
  142. //
  143. NextAttackPage.addChild(NextAttackPageText);
  144. NextAttackPageText.width = 70;
  145. NextAttackPageText.autoSize = TextFieldAutoSize.CENTER;
  146. NextAttackPageText.selectable = false;
  147. NextAttackPageText.mouseEnabled = false;
  148. NextAttackPage.buttonMode = true;
  149. NextAttackPage.addChild(NextAttackPageText);
  150. NextAttackPage.addEventListener(MouseEvent.CLICK, onNextAttackPageClick);
  151. NextAttackPage.graphics.beginFill(0xFFFFFF);
  152. NextAttackPage.graphics.lineStyle(1);
  153. NextAttackPage.graphics.drawRect(0,0,70,32);
  154. NextAttackPage.graphics.endFill();
  155. NextAttackPage.y = 222-40;NextAttackPage.x = 165;
  156. table = new Sprite();
  157. table.graphics.lineStyle(1);
  158. table.graphics.beginFill(0xFFFFFF);
  159. table.graphics.drawRect(0,0,325,50);
  160. table.graphics.endFill();
  161. table.graphics.lineStyle(1);
  162. table.graphics.beginFill(0xFFFFFF);
  163. table.graphics.drawRect(0,50,325,350);
  164. table.graphics.endFill();
  165. table.graphics.lineStyle(1);
  166. table.graphics.beginFill(0xFFFFFF);
  167. table.graphics.drawRect(0,50,128,128);
  168. table.graphics.endFill();
  169. // background.addChild(table);
  170. table.x = 160;table.y=75;
  171. currentTitle = new TextField();
  172. currentTitle.x = 5;
  173. currentTitle.y = 0;
  174. currentTitle.width = 325;
  175. // currentTitle.wordWrap = true;
  176. currentTitle.selectable = false;
  177. currentTitle.mouseEnabled = false;
  178. currentTitle.autoSize = TextFieldAutoSize.CENTER;
  179. table.addChild(currentTitle);
  180. tableExit = new CustomSprite();
  181. tableExit.graphics.beginFill(0xFFFFFF);
  182. tableExit.graphics.lineStyle(1);
  183. tableExit.graphics.drawRect(0,0,25,25);
  184. tableExit.graphics.beginBitmapFill(new XButton());
  185. tableExit.graphics.drawRect(0, 0, 25, 25);
  186. tableExit.graphics.endFill();
  187. tableExit.x=table.width-35;
  188. tableExit.y = 10;
  189. tableExit.buttonMode = true;
  190. tableExit.addEventListener(MouseEvent.CLICK, ontableExitClick);
  191. table.addChild(tableExit);
  192. currentTitle.htmlText = "<font size ='20'>Name</font>";
  193. currentType = new TextField();
  194. currentType.x = 133;
  195. currentType.y = 55;
  196. currentType.width = 187;
  197. //currentType.wordWrap = true;
  198. currentType.selectable = false;
  199. currentType.mouseEnabled = false;
  200. currentType.autoSize = TextFieldAutoSize.RIGHT;
  201. table.addChild(currentType);
  202. currentType.htmlText = "<font size ='20'>Type:</font>";
  203. currentDesc = new TextField();
  204. currentDesc.x = 5;
  205. currentDesc.y = 183;
  206. currentDesc.width = 315;
  207. currentDesc.wordWrap = true;
  208. currentDesc.selectable = false;
  209. currentDesc.mouseEnabled = false;
  210. currentDesc.autoSize = TextFieldAutoSize.CENTER;
  211. table.addChild(currentDesc);
  212. currentDesc.htmlText = "<font size ='20'>Desc</font>";
  213. Text.x = 160; Text.y = 0;
  214. Text.width = 330; Text.height = 55;
  215. background.addChild(Text);
  216. Text.multiline = true;
  217. Text.wordWrap = true;
  218. Text.selectable = false;
  219. var myFormat:TextFormat = new TextFormat();
  220. myFormat.size = 16;
  221. myFormat.align = TextFormatAlign.CENTER;
  222. Text.defaultTextFormat = myFormat;
  223. initAttackMenu();
  224. table.addChild(AttackMenu);
  225. background.addChild(MonsterArchive);
  226. background.addChild(MonsterCurrent);
  227. MonsterPic = new CustomSprite();
  228. table.addChild(MonsterPic);
  229. this.addEventListener("Monster",onMonsterSelected);
  230. //Text.htmlText = "<u>Monsters</u>";
  231. //addChild(QuitButton);
  232. drawMonsterArchive(MonsterPage);
  233. drawMonsterCurrent();
  234. ItemConfirmBackground = new Sprite();
  235. //ItemConfirmBackground.y = (Math.max(512-(31+((buttonPosition)*35)),0))/2;
  236. ItemConfirmBackground.graphics.beginFill(0xFFFFFF);
  237. //ItemConfirmBackground.graphics.lineStyle(1);
  238. ItemConfirmBackground.graphics.drawRect(0,0,160,512-150);
  239. ItemConfirmBackground.y = 195;
  240. ItemConfirmBackground.graphics.endFill();
  241. ItemConfirmBackground.alpha = 0.5;
  242. ItemConfirm = new TextField();
  243. ItemConfirm.background = true;
  244. ItemConfirm.backgroundColor = 0xFFFFFF;
  245. ItemConfirm.htmlText = "<font size='14'>Use Item?</font>";
  246. ItemConfirm.autoSize = TextFieldAutoSize.CENTER;
  247. ItemConfirm.width = (160 - ItemConfirm.width/2);
  248. ItemConfirm.y = 350;
  249. ItemConfirm.selectable = false;
  250. ItemConfirm.mouseEnabled = false;
  251. //ItemConfirm.y = 12;
  252. ItemYes = new Sprite();
  253. var ItemYesText = new TextField();
  254. ItemYesText.htmlText = "<font size='14'>Confirm</font>";
  255. ItemYes.addChild(ItemYesText);
  256. ItemYesText.width = 70;
  257. ItemYesText.autoSize = TextFieldAutoSize.CENTER;
  258. ItemYesText.selectable = false;
  259. ItemYesText.mouseEnabled = false;
  260. ItemYes.buttonMode = true;
  261. ItemYes.addChild(ItemYesText);
  262. ItemYes.addEventListener(MouseEvent.CLICK, onItemYesClick);
  263. ItemYes.graphics.beginFill(0xFFFFFF);
  264. ItemYes.graphics.lineStyle(1);
  265. ItemYes.graphics.drawRect(0,0,70,32);
  266. ItemYes.graphics.endFill();
  267. ItemYes.y = 370;
  268. ItemYes.x = 10;
  269. ItemNo = new Sprite();
  270. ItemNo.mouseChildren = false;
  271. var ItemNoText = new TextField();
  272. ItemNoText.htmlText = "<font size='14'>Cancel</font>";
  273. //
  274. ItemNo.addChild(ItemNoText);
  275. ItemNoText.width = 70;
  276. ItemNoText.autoSize = TextFieldAutoSize.CENTER;
  277. ItemNoText.selectable = false;
  278. ItemNoText.mouseEnabled = false;
  279. ItemNo.buttonMode = true;
  280. ItemNo.addChild(ItemNoText);
  281. ItemNo.addEventListener(MouseEvent.CLICK, onItemNoClick);
  282. ItemNo.graphics.beginFill(0xFFFFFF);
  283. ItemNo.graphics.lineStyle(1);
  284. ItemNo.graphics.drawRect(0,0,70,32);
  285. ItemNo.graphics.endFill();
  286. ItemNo.y = 370;
  287. ItemNo.x = 90;
  288. }
  289. private function onItemYesClick(event:MouseEvent)
  290. {
  291. }
  292. private function onItemNoClick(event:MouseEvent)
  293. {
  294. dispatchEvent(new Event("Cancel"));
  295. }
  296. private function initAttackMenu()
  297. {
  298. AttackMenu = new Sprite();
  299. AttackMenu.y = 178;
  300. AttackMenu.graphics.beginFill(0xFFFFFF);
  301. AttackMenu.graphics.lineStyle(1);
  302. AttackMenu.graphics.drawRect(0,0,325,222);
  303. AttackMenu.graphics.endFill();
  304. }
  305. private function initMonsterCurrent()
  306. {
  307. // if(MonsterCurrent != null)
  308. // {
  309. // while(MonsterCurrent.numChildren != 0)
  310. // {
  311. // MonsterCurrent.removeChildAt(0);
  312. // }
  313. // }
  314. MonsterCurrent = new Sprite();
  315. MonsterCurrent.graphics.lineStyle(1);
  316. MonsterCurrent.graphics.beginFill(0xFFFFFF);
  317. MonsterCurrent.graphics.drawRect(0,0,150,Constants.flashHeight-10);
  318. MonsterCurrent.graphics.endFill();
  319. MonsterCurrent.x = 5; MonsterCurrent.y = 5;
  320. MonsterCurrent.buttonMode = false;
  321. var MonsterCurrentText = new TextField();
  322. MonsterCurrentText.htmlText = "<font size ='18'>Team</font>";
  323. MonsterCurrentText.x = 51;
  324. MonsterCurrentText.y = 2;
  325. MonsterCurrentText.width = 120;
  326. MonsterCurrentText.wordWrap = true;
  327. MonsterCurrentText.selectable = false;
  328. MonsterCurrentText.mouseEnabled = false;
  329. MonsterCurrent.addChild(MonsterCurrentText);
  330. }
  331. private function initMonsterArchive()
  332. {
  333. if(MonsterArchive != null)
  334. {
  335. while(MonsterArchive.numChildren != 0)
  336. {
  337. MonsterArchive.removeChildAt(0);
  338. }
  339. }
  340. MonsterArchive = new Sprite();
  341. MonsterArchive.graphics.lineStyle(1);
  342. MonsterArchive.graphics.beginFill(0xFFFFFF);
  343. MonsterArchive.graphics.drawRect(0,0,320,Constants.flashHeight-10);
  344. MonsterArchive.graphics.endFill();
  345. MonsterArchive.x = 163; MonsterArchive.y = 5;
  346. MonsterArchive.buttonMode = false;
  347. var MonsterArchiveText = new TextField();
  348. MonsterArchiveText.htmlText = "<font size ='18'>Archive</font>";
  349. MonsterArchiveText.x = 80;
  350. MonsterArchiveText.y = 0;
  351. MonsterArchiveText.width = 70;
  352. MonsterArchiveText.height = 70;
  353. MonsterArchiveText.wordWrap = true;
  354. MonsterArchiveText.selectable = false;
  355. MonsterArchiveText.mouseEnabled = false;
  356. MonsterArchive.addChild(MonsterArchiveText);
  357. }
  358. public function redraw()
  359. {
  360. drawMonsterArchive(MonsterPage);
  361. drawMonsterCurrent();
  362. }
  363. private function onExitMenuClick(event:MouseEvent) {
  364. dispatchEvent(new Event("Back"));
  365. }
  366. private function ontableExitClick(event:MouseEvent) {
  367. background.removeChild(table);
  368. }
  369. private function onMonsterSelected (event:MonsterButtonEvent) {
  370. var found = false;
  371. var teamCount = 0;
  372. for (monster in currentTrainer.Monsters)
  373. {
  374. teamCount++;
  375. }
  376. for(monster in currentTrainer.Monsters)
  377. {
  378. if(monster.ID == event.ID)
  379. {
  380. currentMonsterInfo = monster;
  381. if(CurrentState == "")
  382. {
  383. background.addChild(table);
  384. //drawMonsterCurrent();
  385. }
  386. else if(CurrentState == "UseItem")
  387. {
  388. dispatchEvent(new MonsterMenuEvent("Use",monster.ID));
  389. }
  390. else if(CurrentState == "Select")
  391. {
  392. currentTrainer.CurrentMonster = monster;
  393. CurrentState = "";
  394. StatusText.htmlText = "<font size='16'></font>";
  395. drawMonsterCurrent();
  396. }
  397. else if(CurrentState == "Add")
  398. {
  399. StatusText.htmlText = "<font size='16'>Only Add\nFrom Archive</font>";
  400. }
  401. else if(CurrentState == "Archive")
  402. {
  403. if(teamCount <= 1)
  404. {
  405. StatusText.htmlText = "<font size='16'>Must have at least\none Monster in Team</font>";
  406. }
  407. else
  408. {
  409. if(currentTrainer.CurrentMonster.ID == monster.ID)
  410. {
  411. for (monster2 in currentTrainer.Monsters)
  412. {
  413. if(monster2.ID !=monster.ID)
  414. {
  415. currentTrainer.CurrentMonster = monster2;
  416. break;
  417. }
  418. }
  419. }
  420. currentTrainer.MonstersArchive.add(monster);
  421. currentTrainer.Monsters.remove(monster);
  422. StatusText.htmlText = "<font size='16'></font>";
  423. drawMonsterCurrent();
  424. drawMonsterArchive(MonsterPage);
  425. }
  426. }
  427. else if(CurrentState == "Swap")
  428. {
  429. if(currentMonsterArchive != null)
  430. {
  431. if(currentTrainer.CurrentMonster.ID == monster.ID)
  432. {
  433. for (monster2 in currentTrainer.Monsters)
  434. {
  435. if(monster2.ID !=monster.ID)
  436. {
  437. currentTrainer.CurrentMonster = monster2;
  438. break;
  439. }
  440. }
  441. }
  442. currentTrainer.Monsters.remove(monster);
  443. currentTrainer.MonstersArchive.add(monster);
  444. currentTrainer.MonstersArchive.remove(currentMonsterArchive);
  445. currentTrainer.Monsters.add(currentMonsterArchive);
  446. currentMonsterArchive = null;
  447. currentMonster = null;
  448. CurrentState = "";
  449. StatusText.htmlText = "<font size='16'></font>";
  450. drawMonsterCurrent();
  451. drawMonsterArchive(MonsterPage);
  452. }
  453. else
  454. {
  455. currentMonster = monster;
  456. }
  457. }
  458. setupMonster();
  459. found = true;
  460. break;
  461. }
  462. }
  463. if(found)
  464. {return;}
  465. if(CurrentState == "Select")
  466. {
  467. StatusText.htmlText = "<font size='16'>Must Select Monster\nthat is part of\nthe current team</font>";
  468. return;
  469. }
  470. for(monster in currentTrainer.MonstersArchive)
  471. {
  472. if(monster.ID == event.ID)
  473. {
  474. currentMonsterInfo = monster;
  475. setupMonster();
  476. if(CurrentState == "")
  477. {
  478. background.addChild(table);
  479. //drawMonsterArchive();
  480. }
  481. else if(CurrentState == "Select")
  482. {
  483. StatusText.htmlText = "<font size='16'>Select From Team</font>";
  484. }
  485. else if(CurrentState == "Add")
  486. {
  487. if(teamCount < 3)
  488. {
  489. currentTrainer.Monsters.add(monster);
  490. currentTrainer.MonstersArchive.remove(monster);
  491. StatusText.htmlText = "<font size='16'></font>";
  492. }
  493. drawMonsterArchive(MonsterPage);
  494. drawMonsterCurrent();
  495. CurrentState ="";
  496. }
  497. else if(CurrentState == "Swap")
  498. {
  499. if(currentMonster != null)
  500. {
  501. if(currentTrainer.CurrentMonster.ID == currentMonster.ID)
  502. {
  503. for (monster2 in currentTrainer.Monsters)
  504. {
  505. if(monster2.ID !=currentMonster.ID)
  506. {
  507. currentTrainer.CurrentMonster = monster2;
  508. break;
  509. }
  510. }
  511. }
  512. currentTrainer.MonstersArchive.remove(monster);
  513. currentTrainer.Monsters.remove(currentMonster);
  514. currentTrainer.MonstersArchive.add(currentMonster);
  515. currentTrainer.Monsters.add(monster);
  516. currentMonsterArchive = null;
  517. currentMonster = null;
  518. CurrentState = "";
  519. StatusText.htmlText = "<font size='16'></font>";
  520. drawMonsterCurrent();
  521. drawMonsterArchive(MonsterPage);
  522. }
  523. else
  524. {
  525. currentMonsterArchive = monster;
  526. }
  527. }
  528. break;
  529. }
  530. }
  531. }
  532. private function setupMonster()
  533. {
  534. currentTitle.htmlText = "<font size ='20'>"+currentMonsterInfo.Character+ "\n"+ "Level: " + currentMonsterInfo.Level+ " Health: "+ currentMonsterInfo.Health+"/"+currentMonsterInfo.MaxHealth +"</font>";
  535. currentDesc.htmlText = "<font size ='20'>"+ currentMonsterInfo.getMonsterDesc() +"</font>";
  536. currentType.htmlText = "<font size ='20'>"+ "Attack: " + HelperMethods.format(currentMonsterInfo.Attack,2) + "\n"
  537. + "Defense: " + HelperMethods.format(currentMonsterInfo.Defense,2) + "\n"
  538. + "Speed: " + HelperMethods.format(currentMonsterInfo.Speed,2) + "\n"
  539. + "Evasion: " + HelperMethods.format(currentMonsterInfo.Accuracy,2) + "\n"
  540. + "XP: " + HelperMethods.format(currentMonsterInfo.XP,1) + "/" + HelperMethods.format(currentMonsterInfo.XpToNextLevel(),1) + "\n"
  541. + "</font>";
  542. table.removeChild(MonsterPic);
  543. MonsterPic = new CustomSprite();
  544. MonsterPic.graphics.drawRect(0,0,128,128);
  545. MonsterPic.graphics.endFill();
  546. var tileSheetColumn:Int = Std.int(currentMonsterInfo.getTileNumber(false) / 100);
  547. var tileSheetRow:Int = Std.int(currentMonsterInfo.getTileNumber(false) % 100);
  548. var sourceRectangle:Rectangle = new Rectangle
  549. (tileSheetColumn * 64, tileSheetRow * 64, 64,64);
  550. var destinationPoint:Point = new Point(0, 0);
  551. var modelBitmapData = new BitmapData(64, 64, true, 0);
  552. modelBitmapData.copyPixels
  553. (
  554. new BattleSprites(),
  555. sourceRectangle,
  556. destinationPoint,
  557. null, null, true
  558. );
  559. var resizeBitmapData = HelperMethods.resize(128,128,modelBitmapData);
  560. var modelBitmap = new Bitmap(resizeBitmapData);
  561. MonsterPic.addChild(modelBitmap);
  562. table.addChild(MonsterPic);
  563. MonsterPic.y = 50;
  564. drawAttackList(AttackPage);
  565. }
  566. private function drawAttackList(?Page:Int=1)
  567. {
  568. table.removeChild(AttackMenu);
  569. initAttackMenu();
  570. var start = 10*(Page-1);
  571. var finish = 10*Page;
  572. var buttonPosition = 0;
  573. var Title = new TextField();
  574. Title.selectable = false;
  575. Title.htmlText = "<u><font size = '16'>Attack</font></u>";
  576. Title.width = 150;
  577. Title.autoSize = TextFieldAutoSize.CENTER;
  578. //AttackMenu.addChild(Title);
  579. for(move in currentMonsterInfo.Moves)
  580. {
  581. if(buttonPosition < start || buttonPosition >=finish)
  582. {
  583. if(buttonPosition == 0)
  584. {
  585. AttackMenu.addChild(PrevAttackPage);
  586. }
  587. if(buttonPosition == finish+1)
  588. {
  589. AttackMenu.addChild(NextAttackPage);
  590. }
  591. buttonPosition++;
  592. continue;
  593. }
  594. var Attack = new AttackButton(move);
  595. var column = 0;
  596. var pagePosition = (buttonPosition-((Page-1)*5));
  597. if(pagePosition >= 5)
  598. {
  599. column = 1;
  600. }
  601. Attack.x = 5+(column*160);Attack.y=5+((pagePosition-(column*5))*35);
  602. AttackMenu.addChild(Attack);
  603. buttonPosition++;
  604. }
  605. table.addChild(AttackMenu);
  606. }
  607. private function drawMonsterArchive(?Page:Int=1)
  608. {
  609. background.removeChild(MonsterArchive);
  610. initMonsterArchive();
  611. var start = 16*(Page-1);
  612. var finish = 16*Page;
  613. var buttonPosition = 0;
  614. for(monster in currentTrainer.MonstersArchive)
  615. {
  616. if(buttonPosition < start || buttonPosition >=finish)
  617. {
  618. if(buttonPosition == 0)
  619. {
  620. MonsterArchive.addChild(PrevMonsterPage);
  621. }
  622. if(buttonPosition == finish+1)
  623. {
  624. MonsterArchive.addChild(NextMonsterPage);
  625. }
  626. buttonPosition++;
  627. continue;
  628. }
  629. var MonsterIcon = new MonsterButton(monster,true);
  630. var pagePosition = (buttonPosition-((Page-1)*16));
  631. var column = 0;
  632. if (pagePosition >= 8)
  633. {
  634. column = 1;
  635. }
  636. MonsterIcon.x = 10+155*column;MonsterIcon.y=26+((pagePosition-(column*8))*55);
  637. MonsterArchive.addChild(MonsterIcon);
  638. buttonPosition++;
  639. }
  640. background.addChild(MonsterArchive);
  641. }
  642. private function drawMonsterCurrent()
  643. {
  644. background.removeChild(MonsterCurrent);
  645. initMonsterCurrent();
  646. var buttonPosition = 0;
  647. var currentImage = new TextField();
  648. currentImage.htmlText = "<font size ='14'><b>Current</b></font>";
  649. currentImage.x = 40;
  650. currentImage.y = -5;
  651. currentImage.width = 70;
  652. currentImage.height = 30;
  653. currentImage.background = false;
  654. currentImage.backgroundColor = 0xFFFFFF;
  655. currentImage.wordWrap = true;
  656. currentImage.selectable = false;
  657. currentImage.mouseEnabled = false;
  658. MonsterArchive.addChild(currentImage);
  659. for(monster in currentTrainer.Monsters)
  660. {
  661. var MonsterIcon = new MonsterButton(monster,true);
  662. if(monster.ID == currentTrainer.CurrentMonster.ID)
  663. {
  664. MonsterIcon.addChild(currentImage);
  665. }
  666. MonsterIcon.x = 5;MonsterIcon.y=26+((buttonPosition)*55);
  667. MonsterCurrent.addChild(MonsterIcon);
  668. buttonPosition++;
  669. }
  670. var selectMonster = new Sprite();
  671. selectMonster.graphics.beginFill(0xFFFFFF);
  672. selectMonster.graphics.lineStyle(1);
  673. selectMonster.graphics.drawRect(0,0,140,50);
  674. selectMonster.graphics.endFill();
  675. selectMonster.buttonMode = true;
  676. var selectMonsterText = new TextField();
  677. selectMonsterText.htmlText = "<font size='16'>Select Current\nMonster</font>";
  678. //
  679. selectMonster.addChild(selectMonsterText);
  680. selectMonsterText.width = 140;
  681. selectMonsterText.autoSize = TextFieldAutoSize.LEFT;
  682. selectMonsterText.selectable = false;
  683. selectMonsterText.mouseEnabled = false;
  684. selectMonster.addEventListener(MouseEvent.CLICK, onSelectMonsterClick);
  685. selectMonster.x = 5;
  686. selectMonster.y = 26+((3)*55);
  687. MonsterCurrent.addChild(selectMonster);
  688. buttonPosition++;
  689. var SwapMonster = new Sprite();
  690. SwapMonster.graphics.beginFill(0xFFFFFF);
  691. SwapMonster.graphics.lineStyle(1);
  692. SwapMonster.graphics.drawRect(0,0,140,50);
  693. SwapMonster.graphics.endFill();
  694. SwapMonster.buttonMode = true;
  695. var SwapMonsterText = new TextField();
  696. SwapMonsterText.htmlText = "<font size='16'>Swap Current\nMonster</font>";
  697. //
  698. SwapMonster.addChild(SwapMonsterText);
  699. SwapMonsterText.width = 140;
  700. SwapMonsterText.autoSize = TextFieldAutoSize.LEFT;
  701. SwapMonsterText.selectable = false;
  702. SwapMonsterText.mouseEnabled = false;
  703. SwapMonster.addEventListener(MouseEvent.CLICK, onSwapMonsterClick);
  704. SwapMonster.x = 5;
  705. SwapMonster.y = 26+((4)*55);
  706. MonsterCurrent.addChild(SwapMonster);
  707. buttonPosition++;
  708. var ArchiveMonster = new Sprite();
  709. ArchiveMonster.graphics.beginFill(0xFFFFFF);
  710. ArchiveMonster.graphics.lineStyle(1);
  711. ArchiveMonster.graphics.drawRect(0,0,140,50);
  712. ArchiveMonster.graphics.endFill();
  713. ArchiveMonster.buttonMode = true;
  714. var ArchiveMonsterText = new TextField();
  715. ArchiveMonsterText.htmlText = "<font size='16'>Archive Current\nMonster</font>";
  716. //
  717. ArchiveMonster.addChild(ArchiveMonsterText);
  718. ArchiveMonsterText.width = 140;
  719. ArchiveMonsterText.autoSize = TextFieldAutoSize.LEFT;
  720. ArchiveMonsterText.selectable = false;
  721. ArchiveMonsterText.mouseEnabled = false;
  722. ArchiveMonster.addEventListener(MouseEvent.CLICK, onArchiveMonsterClick);
  723. ArchiveMonster.x = 5;
  724. ArchiveMonster.y = 26+((5)*55);
  725. MonsterCurrent.addChild(ArchiveMonster);
  726. buttonPosition++;
  727. var AddMonster = new Sprite();
  728. AddMonster.graphics.beginFill(0xFFFFFF);
  729. AddMonster.graphics.lineStyle(1);
  730. AddMonster.graphics.drawRect(0,0,140,50);
  731. AddMonster.graphics.endFill();
  732. AddMonster.buttonMode = true;
  733. var AddMonsterText = new TextField();
  734. AddMonsterText.htmlText = "<font size='16'>Add Current\nMonster</font>";
  735. //
  736. AddMonster.addChild(AddMonsterText);
  737. AddMonsterText.width = 140;
  738. AddMonsterText.autoSize = TextFieldAutoSize.LEFT;
  739. AddMonsterText.selectable = false;
  740. AddMonsterText.mouseEnabled = false;
  741. AddMonster.addEventListener(MouseEvent.CLICK, onAddMonsterClick);
  742. AddMonster.x = 5;
  743. AddMonster.y = 26+((6)*55);
  744. MonsterCurrent.addChild(AddMonster);
  745. buttonPosition++;
  746. Status = new Sprite();
  747. Status.graphics.beginFill(0xFFFFFF);
  748. Status.graphics.lineStyle(1);
  749. Status.graphics.drawRect(0,0,140,85);
  750. Status.graphics.endFill();
  751. Status.buttonMode = false;
  752. StatusText = new TextField();
  753. StatusText.htmlText = "<font size='16'></font>";
  754. //
  755. Status.addChild(StatusText);
  756. StatusText.width = 140;
  757. StatusText.autoSize = TextFieldAutoSize.CENTER;
  758. StatusText.selectable = false;
  759. StatusText.mouseEnabled = false;
  760. Status.x = 5;
  761. Status.y = 26+((7)*55);
  762. MonsterCurrent.addChild(Status);
  763. background.addChild(MonsterCurrent);
  764. }
  765. private function onSelectMonsterClick(event:MouseEvent)
  766. {
  767. CurrentState = "Select";
  768. StatusText.htmlText = "<font size='16'>Selecting</font>";
  769. }
  770. private function onSwapMonsterClick(event:MouseEvent)
  771. {
  772. CurrentState = "Swap";
  773. StatusText.htmlText = "<font size='16'>Swaping</font>";
  774. currentMonster = null;
  775. currentMonsterArchive = null;
  776. }
  777. private function onArchiveMonsterClick(event:MouseEvent)
  778. {
  779. CurrentState = "Archive";
  780. StatusText.htmlText = "<font size='16'>Archiveing</font>";
  781. var teamCount = 0;
  782. for (monster in currentTrainer.Monsters)
  783. {
  784. teamCount ++;
  785. }
  786. if(teamCount <= 1)
  787. {
  788. StatusText.htmlText = "<font size='16'>Must have at least\none monster\nin the team</font>";
  789. }
  790. }
  791. private function onAddMonsterClick(event:MouseEvent)
  792. {
  793. CurrentState = "Add";
  794. StatusText.htmlText = "<font size='16'>Adding</font>";
  795. var teamCount = 0;
  796. for (monster in currentTrainer.Monsters)
  797. {
  798. teamCount++;
  799. }
  800. if(teamCount >= 3)
  801. {
  802. StatusText.htmlText = "<font size='16'>No more than\nthree Monsters\nin the team</font>";
  803. }
  804. }
  805. private function onPrevMonsterPageClick(event:MouseEvent)
  806. {
  807. MonsterPage--;
  808. drawMonsterArchive(MonsterPage);
  809. }
  810. private function onNextMonsterPageClick(event:MouseEvent)
  811. {
  812. MonsterPage++;
  813. drawMonsterArchive(MonsterPage);
  814. }
  815. private function onPrevAttackPageClick(event:MouseEvent)
  816. {
  817. AttackPage--;
  818. drawAttackList(AttackPage);
  819. }
  820. private function onNextAttackPageClick(event:MouseEvent)
  821. {
  822. AttackPage++;
  823. drawAttackList(AttackPage);
  824. }
  825. }