/GameEngine/src/com/lushu/chapitre1/graphics/controls/BattleInformation.as

http://shining-fluff-devkit.googlecode.com/ · ActionScript · 273 lines · 228 code · 45 blank · 0 comment · 27 complexity · 33a0bdaab76d716ea977372cfb733d50 MD5 · raw file

  1. package com.lushu.chapitre1.graphics.controls
  2. {
  3. import com.sfdk.graphics.core.SpriteEx;
  4. import com.sfdk.graphics.core.TextFieldEx;
  5. import com.sfdk.graphics.engine.data.CharacterDefinition;
  6. import com.sfdk.graphics.ui.parts.ComponentBase;
  7. import com.sfdk.locale.LocalisedMessageEngine;
  8. import com.sfdk.pools.BitmapDataPool;
  9. import flash.display.Bitmap;
  10. import flash.display.BitmapData;
  11. import flash.display.Graphics;
  12. import flash.events.Event;
  13. public class BattleInformation extends ComponentBase
  14. {
  15. private var _landEffect:SpriteEx;
  16. private var _landEffectContainer:Bitmap;
  17. private var _landEffectTF:TextFieldEx;
  18. private var _landEffectPercentTF:TextFieldEx;
  19. private var _characterInfoContainer:Bitmap;
  20. private var _characterInfoLeftTF:TextFieldEx;
  21. private var _characterInfoRightTF:TextFieldEx;
  22. private var _hpContainer:SpriteEx;
  23. private var _mpContainer:SpriteEx;
  24. private var _enemyInfo:SpriteEx;
  25. private var _enemyInfoContainer:Bitmap;
  26. private var _enemyInfoLeftTF:TextFieldEx;
  27. private var _enemyInfoRightTF:TextFieldEx;
  28. private var _enemyHPContainer:SpriteEx;
  29. private var _enemyMPContainer:SpriteEx;
  30. private var _currentCharacterDefinition:CharacterDefinition;
  31. private var _currentTileInfo:int = 15;
  32. private var _currentEnemyDefinition:CharacterDefinition;
  33. public function BattleInformation() {
  34. super();
  35. }
  36. override protected function createChildren():void {
  37. super.createChildren();
  38. _landEffect = new SpriteEx();
  39. _landEffectContainer = BitmapDataPool.instance.getAsBitmap("resources/images/landEffectContainer.png");
  40. _landEffectTF = new TextFieldEx("SFSys-12");
  41. _landEffectPercentTF = new TextFieldEx("SFSys-12-Right");
  42. _landEffectPercentTF.width = 50;
  43. _characterInfoContainer = BitmapDataPool.instance.getAsBitmap("resources/images/characterInfoContainer.png");
  44. _characterInfoLeftTF = new TextFieldEx("SFSys-12");
  45. _characterInfoLeftTF.width = 140;
  46. _characterInfoRightTF = new TextFieldEx("SFSys-12-Right");
  47. _hpContainer = new SpriteEx();
  48. _mpContainer = new SpriteEx();
  49. _enemyInfo = new SpriteEx();
  50. _enemyInfoContainer = BitmapDataPool.instance.getAsBitmap("resources/images/enemyInfoContainer.png");
  51. _enemyInfoLeftTF = new TextFieldEx("SFSys-12");
  52. _enemyInfoLeftTF.width = 140;
  53. _enemyInfoRightTF = new TextFieldEx("SFSys-12-Right");
  54. _enemyHPContainer = new SpriteEx();
  55. _enemyMPContainer = new SpriteEx();
  56. }
  57. override protected function cleanView(e:Event):void {
  58. super.cleanView(e);
  59. }
  60. override protected function createView(e:Event):void {
  61. super.createView(e);
  62. attachChild(_landEffect, 0, 0, "landEffect");
  63. _landEffect.attachChild(_landEffectContainer, 0, 0, "landEffectContainer");
  64. _landEffect.attachChild(_landEffectTF, 16, 14, "landEffectTF");
  65. _landEffectTF.text = LocalisedMessageEngine.getMessage("LAND_EFFECT");
  66. _landEffect.attachChild(_landEffectPercentTF, 65, 47, "landEffectPercentTF");
  67. attachChild(_characterInfoContainer, 224, 0, "characterInfoContainer");
  68. attachChild(_characterInfoLeftTF, 240, 14, "characterInfoLeftTF");
  69. attachChild(_characterInfoRightTF, 348, 14, "characterInfoRightTF");
  70. attachChild(_hpContainer, 274, 32, "hpContainer");
  71. attachChild(_mpContainer, 274, 48, "mpContainer");
  72. _enemyInfo.visible = false;
  73. attachChild(_enemyInfo, 288, 330, "enemyInfo");
  74. _enemyInfo.attachChild(_enemyInfoContainer, 0, 0, "enemyInfoContainer");
  75. _enemyInfo.attachChild(_enemyInfoLeftTF, 16, 14, "enemyInfoLeftTF");
  76. _enemyInfo.attachChild(_enemyInfoRightTF, 60, 14, "enemyInfoRightTF");
  77. _enemyInfo.attachChild(_enemyHPContainer, 50, 32, "enemyHPContainer");
  78. _enemyInfo.attachChild(_enemyMPContainer, 50, 48, "enemyMPContainer");
  79. setCurrentTileInfo(15);
  80. }
  81. public function setCurrentCharacter(characterDefinition:CharacterDefinition):void {
  82. _currentCharacterDefinition = characterDefinition;
  83. _characterInfoLeftTF.text = _currentCharacterDefinition.name.toUpperCase() + "\n" + LocalisedMessageEngine.getMessage("HP") + "\n" + LocalisedMessageEngine.getMessage("MP");
  84. _characterInfoRightTF.text = _currentCharacterDefinition.characterClass.toUpperCase() + _currentCharacterDefinition.stats["lv"] + "\n" + _currentCharacterDefinition.stats["hp"] + " / " + _currentCharacterDefinition.stats["maxHp"] + "\n" + _currentCharacterDefinition.stats["mp"] + " / " + _currentCharacterDefinition.stats["maxMp"];
  85. var hp:int = _currentCharacterDefinition.stats["hp"];
  86. var maxHp:int = _currentCharacterDefinition.stats["maxHp"];
  87. var mp:int = _currentCharacterDefinition.stats["mp"];
  88. var maxMp:int = _currentCharacterDefinition.stats["maxMp"];
  89. var hpG:BitmapData = new BitmapData(4 + maxHp * 2, 14, true, 0);
  90. for (var i:int = 2; i <= 2 + maxHp * 2; i++) {
  91. hpG.setPixel32(i, 0, 0xFFFFFFFF);
  92. hpG.setPixel32(i, 1, 0xFFFFFFFF);
  93. hpG.setPixel32(i, 13, 0xFFFFFFFF);
  94. hpG.setPixel32(i, 14, 0xFFFFFFFF);
  95. }
  96. for (i = 2; i <= 12; i++) {
  97. hpG.setPixel32(0, i, 0xFFFFFFFF);
  98. hpG.setPixel32(1, i, 0xFFFFFFFF);
  99. hpG.setPixel32(4 + maxHp * 2, i, 0xFFFFFFFF);
  100. hpG.setPixel32(3 + maxHp * 2, i, 0xFFFFFFFF);
  101. }
  102. hpG.floodFill(2 + maxMp * 2, 4, 0xFFC52121);
  103. if (hp > 0) {
  104. if (hp < maxHp) {
  105. for (i = 2; i <= 12; i++) {
  106. hpG.setPixel32(2 + hp * 2, i, 0xFFE6C542);
  107. }
  108. }
  109. hpG.floodFill(4, 4, 0xFFE6C542);
  110. }
  111. var hpGra:Graphics = _hpContainer.graphics;
  112. hpGra.clear();
  113. hpGra.beginBitmapFill(hpG);
  114. hpGra.drawRect(0, 0, 5 + maxHp * 2, 15);
  115. if (maxMp != 0) {
  116. var mpG:BitmapData = new BitmapData(4 + maxHp * 2, 14, true, 0);
  117. for (i = 2; i <= 2 + maxMp * 2; i++) {
  118. mpG.setPixel32(i, 0, 0xFFFFFFFF);
  119. mpG.setPixel32(i, 1, 0xFFFFFFFF);
  120. mpG.setPixel32(i, 13, 0xFFFFFFFF);
  121. mpG.setPixel32(i, 14, 0xFFFFFFFF);
  122. }
  123. for (i = 2; i <= 12; i++) {
  124. mpG.setPixel32(0, i, 0xFFFFFFFF);
  125. mpG.setPixel32(1, i, 0xFFFFFFFF);
  126. mpG.setPixel32(4 + maxMp * 2, i, 0xFFFFFFFF);
  127. mpG.setPixel32(3 + maxMp * 2, i, 0xFFFFFFFF);
  128. }
  129. mpG.floodFill(2 + maxMp * 2, 4, 0xFFC52121);
  130. if (mp > 0) {
  131. if (mp < maxMp) {
  132. for (i = 2; i <= 12; i++) {
  133. mpG.setPixel32(2 + mp * 2, i, 0xFFE6C542);
  134. }
  135. }
  136. mpG.floodFill(4, 4, 0xFFE6C542);
  137. }
  138. var mpGra:Graphics = _mpContainer.graphics;
  139. mpGra.clear();
  140. mpGra.beginBitmapFill(mpG);
  141. mpGra.drawRect(0, 0, 5 + maxMp * 2, 15);
  142. }
  143. }
  144. public function setCurrentEnemy(characterDefinition:CharacterDefinition):void {
  145. _currentEnemyDefinition = characterDefinition;
  146. if (characterDefinition == null) {
  147. _enemyInfo.visible = false;
  148. }
  149. else {
  150. _enemyInfo.visible = true;
  151. _enemyInfoLeftTF.text = _currentEnemyDefinition.name.toUpperCase() + "\n" + LocalisedMessageEngine.getMessage("HP") + "\n" + LocalisedMessageEngine.getMessage("MP");
  152. _enemyInfoRightTF.text = "\n" + _currentEnemyDefinition.stats["hp"] + "/ " + _currentEnemyDefinition.stats["maxHp"] + "\n" + _currentEnemyDefinition.stats["mp"] + "/ " + _currentEnemyDefinition.stats["maxMp"];
  153. var hp:int = _currentEnemyDefinition.stats["hp"];
  154. var maxHp:int = _currentEnemyDefinition.stats["maxHp"];
  155. var mp:int = _currentEnemyDefinition.stats["mp"];
  156. var maxMp:int = _currentEnemyDefinition.stats["maxMp"];
  157. var hpG:BitmapData = new BitmapData(4 + maxHp * 2, 14, true, 0);
  158. for (var i:int = 2; i <= 2 + maxHp * 2; i++) {
  159. hpG.setPixel32(i, 0, 0xFFFFFFFF);
  160. hpG.setPixel32(i, 1, 0xFFFFFFFF);
  161. hpG.setPixel32(i, 13, 0xFFFFFFFF);
  162. hpG.setPixel32(i, 14, 0xFFFFFFFF);
  163. }
  164. for (i = 2; i <= 12; i++) {
  165. hpG.setPixel32(0, i, 0xFFFFFFFF);
  166. hpG.setPixel32(1, i, 0xFFFFFFFF);
  167. hpG.setPixel32(4 + maxHp * 2, i, 0xFFFFFFFF);
  168. hpG.setPixel32(3 + maxHp * 2, i, 0xFFFFFFFF);
  169. }
  170. hpG.floodFill(2 + maxMp * 2, 4, 0xFFC52121);
  171. if (hp > 0) {
  172. if (hp < maxHp) {
  173. for (i = 2; i <= 12; i++) {
  174. hpG.setPixel32(2 + hp * 2, i, 0xFFE6C542);
  175. }
  176. }
  177. hpG.floodFill(4, 4, 0xFFE6C542);
  178. }
  179. var hpGra:Graphics = _enemyHPContainer.graphics;
  180. hpGra.clear();
  181. hpGra.beginBitmapFill(hpG);
  182. hpGra.drawRect(0, 0, 5 + maxHp * 2, 15);
  183. if (maxMp != 0) {
  184. var mpG:BitmapData = new BitmapData(4 + maxHp * 2, 14, true, 0);
  185. for (i = 2; i <= 2 + maxMp * 2; i++) {
  186. mpG.setPixel32(i, 0, 0xFFFFFFFF);
  187. mpG.setPixel32(i, 1, 0xFFFFFFFF);
  188. mpG.setPixel32(i, 13, 0xFFFFFFFF);
  189. mpG.setPixel32(i, 14, 0xFFFFFFFF);
  190. }
  191. for (i = 2; i <= 12; i++) {
  192. mpG.setPixel32(0, i, 0xFFFFFFFF);
  193. mpG.setPixel32(1, i, 0xFFFFFFFF);
  194. mpG.setPixel32(4 + maxMp * 2, i, 0xFFFFFFFF);
  195. mpG.setPixel32(3 + maxMp * 2, i, 0xFFFFFFFF);
  196. }
  197. mpG.floodFill(2 + maxMp * 2, 4, 0xFFC52121);
  198. if (mp > 0) {
  199. if (mp < maxMp) {
  200. for (i = 2; i <= 12; i++) {
  201. mpG.setPixel32(2 + mp * 2, i, 0xFFE6C542);
  202. }
  203. }
  204. mpG.floodFill(4, 4, 0xFFE6C542);
  205. }
  206. var mpGra:Graphics = _enemyMPContainer.graphics;
  207. mpGra.clear();
  208. mpGra.beginBitmapFill(mpG);
  209. mpGra.drawRect(0, 0, 5 + maxMp * 2, 15);
  210. }
  211. }
  212. }
  213. public function setCurrentTileInfo(tileInfo:int):void {
  214. _currentTileInfo = tileInfo;
  215. _landEffectPercentTF.text = _currentTileInfo + "%";
  216. }
  217. public function hideLandEffect():void {
  218. _landEffect.visible = false;
  219. }
  220. public function showLandEffect():void {
  221. _landEffect.visible = true;
  222. }
  223. public function moveEnemyInformation(tx:int, ty:int):void {
  224. _enemyInfo.x = tx;
  225. _enemyInfo.y = ty;
  226. }
  227. }
  228. }