unitGroup.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. this.initialize = function() {
  2. if ( this.icon !== undefined && this.icon.imageGenerator !== undefined ) {
  3. this.icon.imageGenerator.affiliationChanged = this.events.add( function( affiliation ) {
  4. if ( this.threatArea ) {
  5. switch ( affiliation ) {
  6. case "hostile":
  7. this.threatArea.fill = 'red';
  8. break;
  9. case "neutral":
  10. this.threatArea.fill = 'lime';
  11. break;
  12. case "friendly":
  13. this.threatArea.fill = 'lightblue';
  14. break;
  15. default:
  16. this.threatArea.fill = 'yellow';
  17. break;
  18. }
  19. }
  20. }, this );
  21. this.icon.imageGenerator.imageRendered = this.events.add( function( img, iconSize, symbolCenter, symbolBounds ) {
  22. if ( this.threatArea ) {
  23. this.threatArea.position = this.icon.symbolCenter;
  24. }
  25. if ( this.border ) {
  26. this.border.points = [
  27. 0, 0,
  28. iconSize.width, 0,
  29. iconSize.width, iconSize.height,
  30. 0, iconSize.height,
  31. 0, 0
  32. ];
  33. }
  34. }, this );
  35. }
  36. }
  37. this.handleRender = function( img, iconSize, symbolCenter, symbolBounds ){
  38. if ( this.threatArea ) {
  39. this.threatArea.position = this.icon.symbolCenter;
  40. }
  41. if ( this.border ) {
  42. this.border.points = [
  43. 0, 0,
  44. iconSize.width, 0,
  45. iconSize.width, iconSize.height,
  46. 0, iconSize.height,
  47. 0, 0
  48. ];
  49. }
  50. }
  51. this.updateThreatShape = function() {
  52. var visible = false;
  53. if ( this.threatArea ) {
  54. visible = this.threatArea.visible;
  55. this.children.delete( this.threatArea );
  56. }
  57. var newShape = undefined;
  58. var color = 'yellow';
  59. if ( this.icon && this.icon.imageGenerator ) {
  60. switch ( this.icon.imageGenerator.affiliation ) {
  61. case "hostile":
  62. color = 'red';
  63. break;
  64. case "neutral":
  65. color = 'lime';
  66. break;
  67. case "friendly":
  68. color = 'lightblue';
  69. break;
  70. };
  71. }
  72. switch ( this.threatShape ) {
  73. case "rect":
  74. newShape = {
  75. "extends": "http://vwf.example.com/kinetic/rect.vwf",
  76. "properties": {
  77. "x": 20,
  78. "y": 20,
  79. "visible": visible,
  80. "listening": false,
  81. "width": 40,
  82. "height": 40,
  83. "opacity": 0.3,
  84. "fill": color,
  85. "fillEnabled": true,
  86. "draggable": false,
  87. "zIndex": 2
  88. }
  89. };
  90. break;
  91. case "circle":
  92. newShape = {
  93. "extends": "http://vwf.example.com/kinetic/circle.vwf",
  94. "properties": {
  95. "x": 16,
  96. "y": 16,
  97. "visible": visible,
  98. "listening": false,
  99. "radius": 32,
  100. "opacity": 0.3,
  101. "fill": color,
  102. "fillEnabled": true,
  103. "draggable": false,
  104. "zIndex": 2
  105. }
  106. };
  107. break;
  108. case "wedge":
  109. newShape = {
  110. "extends": "http://vwf.example.com/kinetic/wedge.vwf",
  111. "properties": {
  112. "x": 16,
  113. "y": 16,
  114. "visible": visible,
  115. "listening": false,
  116. "width": 40,
  117. "height": 40,
  118. "angle": 40,
  119. "radius": 32,
  120. "opacity": 0.3,
  121. "fill": color,
  122. "fillEnabled": true,
  123. "draggable": false,
  124. "zIndex": 2
  125. }
  126. };
  127. break;
  128. default:
  129. this.logger.info( "Unknown threat shape: " + this.threatShape );
  130. break;
  131. }
  132. if ( newShape ) {
  133. this.children.create( "threatArea", newShape );
  134. this.threatShapeChanged( this.threatShape );
  135. }
  136. }
  137. //@ sourceURL=unitGroup.js