not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.7 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var sizepalette = {};
  4. sizepalette.SizePalette = function (game, invoker, primaryText, menuData) {
  5. console.log(game);
  6. console.log(invoker);
  7. palette.Palette.call(this, invoker, primaryText);
  8. var div = document.createElement('div');
  9. var fourbutton = document.createElement('button');
  10. fourbutton.className = 'toolbutton';
  11. fourbutton.setAttribute('id','four-button');
  12. fourbutton.setAttribute('data-l10n-id','four-button');
  13. fourbutton.setAttribute('title','4x4 grid');
  14. fourbutton.onclick = function() {
  15. that.setSize(4);
  16. }
  17. var fivebutton = document.createElement('button');
  18. fivebutton.className = 'toolbutton';
  19. fivebutton.setAttribute('id','five-button');
  20. fivebutton.setAttribute('data-l10n-id','five-button');
  21. fivebutton.setAttribute('title','5x5 grid');
  22. fivebutton.onclick = function() {
  23. that.setSize(5);
  24. }
  25. var sixbutton = document.createElement('button');
  26. sixbutton.className = 'toolbutton';
  27. sixbutton.setAttribute('id','six-button');
  28. sixbutton.setAttribute('data-l10n-id','six-button');
  29. sixbutton.setAttribute('title','6x6 grid');
  30. sixbutton.onclick = function() {
  31. that.setSize(6);
  32. }
  33. var sevenbutton = document.createElement('button');
  34. sevenbutton.className = 'toolbutton';
  35. sevenbutton.setAttribute('id','seven-button');
  36. sevenbutton.setAttribute('data-l10n-id','seven-button');
  37. sevenbutton.setAttribute('title','7x7 grid');
  38. sevenbutton.onclick = function() {
  39. that.setSize(7);
  40. }
  41. this.setSize = function(state) {
  42. that.popDown();
  43. g.setSize(state);
  44. that.setUsed();
  45. }
  46. this.resetBackgroundCols = function(){
  47. fourbutton.style.backgroundColor = "#C0C0C0";
  48. fivebutton.style.backgroundColor = "#C0C0C0";
  49. sixbutton.style.backgroundColor = "#C0C0C0";
  50. sevenbutton.style.backgroundColor = "#C0C0C0";
  51. }
  52. this.setUsed = function(){
  53. this.resetBackgroundCols();
  54. var sizebutton = document.getElementById("size-button");
  55. //TODO: This is a hack - more palettes will break it.
  56. var sizepalettebutton = document.getElementsByClassName("palette-invoker")[1];
  57. switch(game.startgridwidth) {
  58. case 4:
  59. sizebutton.style.backgroundImage = "url(icons/4x4.svg)";
  60. sizepalettebutton.style.backgroundImage = "url(icons/4x4.svg)";
  61. fourbutton.style.backgroundColor = "#808080";
  62. break;
  63. case 5:
  64. sizebutton.style.backgroundImage = "url(icons/5x5.svg)";
  65. sizepalettebutton.style.backgroundImage = "url(icons/5x5.svg)";
  66. fivebutton.style.backgroundColor = "#808080";
  67. break;
  68. case 6:
  69. sizebutton.style.backgroundImage = "url(icons/6x6.svg)";
  70. sizepalettebutton.style.backgroundImage = "url(icons/6x6.svg)";
  71. sixbutton.style.backgroundColor = "#808080";
  72. break;
  73. case 7:
  74. sizebutton.style.backgroundImage = "url(icons/7x7.svg)";
  75. sizepalettebutton.style.backgroundImage = "url(icons/7x7.svg)";
  76. sevenbutton.style.backgroundColor = "#808080";
  77. break;
  78. }
  79. }
  80. div.appendChild(fourbutton);
  81. div.appendChild(fivebutton);
  82. div.appendChild(sixbutton);
  83. div.appendChild(sevenbutton);
  84. this.setContent([div]);
  85. var that = this;
  86. var g = game;
  87. };
  88. var addEventListener = function (type, listener, useCapture) {
  89. return this.getPalette().addEventListener(type, listener, useCapture);
  90. };
  91. sizepalette.SizePalette.prototype =
  92. Object.create(palette.Palette.prototype, {
  93. addEventListener: {
  94. value: addEventListener,
  95. enumerable: true,
  96. configurable: true,
  97. writable: true
  98. }
  99. });
  100. sizepalette.SizePalette.prototype.setShared = function(state) {
  101. this.setShared(state);
  102. }
  103. return sizepalette;
  104. });