Field/FieldPosition.js

  1. // ПОЗИЦИОНИРОВАНИЕ ПОЛЯ
  2. /**
  3. * Устанавливает позицию поля.
  4. * @param {number} [x=this.style.x] по горизонтали
  5. * @param {number} [y=this.style.y] по вертикали
  6. * @param {boolean} [shouldPlace=false] нужно ли размещать карты после установки
  7. */
  8. Field.prototype.setBase = function(x, y, shouldPlace){
  9. if(x === null || x === undefined){
  10. x = this.style.x;
  11. }
  12. if(y === null || y === undefined){
  13. y = this.style.y;
  14. }
  15. if(shouldPlace === undefined){
  16. shouldPlace = false;
  17. }
  18. this.endAnimation();
  19. this.x = this.style.x = Math.round(x);
  20. this.y = this.style.y = Math.round(y);
  21. if(shouldPlace){
  22. this.placeCards();
  23. }
  24. };
  25. /**
  26. * Устанавливает размер поля.
  27. * @param {number} [width=this.style.width] ширина
  28. * @param {number} [height=this.style.height] высота
  29. * @param {boolean} [shouldPlace=false] нужно ли размещать карты после установки
  30. */
  31. Field.prototype.setSize = function(width, height, shouldPlace){
  32. if(width === null || width === undefined){
  33. width = this.style.width;
  34. }
  35. else{
  36. this.style.width = width;
  37. }
  38. if(height === null || height === undefined){
  39. height = this.style.height;
  40. }
  41. else{
  42. this.style.height = height;
  43. }
  44. if(shouldPlace === undefined){
  45. shouldPlace = false;
  46. }
  47. var margin = this.style.margin;
  48. if(this.style.axis == 'vertical'){
  49. if(width - margin*2 < skinManager.skin.height){
  50. width = skinManager.skin.height + margin*2;
  51. }
  52. if(height - margin*2 < skinManager.skin.width + this.style.minActiveSpace){
  53. height = skinManager.skin.width + this.style.minActiveSpace + margin*2;
  54. }
  55. }
  56. else{
  57. if(width - margin*2 < skinManager.skin.width + this.style.minActiveSpace){
  58. width = skinManager.skin.width + this.style.minActiveSpace + margin*2;
  59. }
  60. if(height - margin*2 < skinManager.skin.height){
  61. height = skinManager.skin.height + margin*2;
  62. }
  63. }
  64. width = Math.round(width + this.style.padding*2);
  65. height = Math.round(height + this.style.padding*2);
  66. this._createArea(width, height);
  67. if(shouldPlace){
  68. this.placeCards();
  69. }
  70. };
  71. /**
  72. * Запоминает размеры поля и рисует прямоугольник с закругленными углами.
  73. * @param {number} width ширина поля
  74. * @param {number} height высота поля
  75. */
  76. Field.prototype._createArea = function(width, height){
  77. Menu.drawRoundedRectangle(
  78. this._bitmapArea,
  79. width,
  80. height,
  81. this.style.margin,
  82. this.style.margin,
  83. this.style.corner,
  84. this.style.border,
  85. 0.65,
  86. 'rgba(255, 255, 255, 1)',
  87. 'rgba(255, 255, 255, 1)'
  88. );
  89. this.area.texture.requiresReTint = true;
  90. };