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.

184 lines
5.7 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var abacuspalette = {};
  4. abacuspalette.AbacusPalette = 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 decimalbutton = document.createElement('button');
  10. decimalbutton.className = 'toolbutton';
  11. decimalbutton.setAttribute('id','decimal-button');
  12. decimalbutton.setAttribute('title','Decimal');
  13. decimalbutton.onclick = function() {
  14. that.setAbacus(0);
  15. }
  16. var sorobanbutton = document.createElement('button');
  17. sorobanbutton.className = 'toolbutton';
  18. sorobanbutton.setAttribute('id','soroban-button');
  19. sorobanbutton.setAttribute('title','Soroban');
  20. sorobanbutton.onclick = function() {
  21. that.setAbacus(1);
  22. }
  23. var suanpanbutton = document.createElement('button');
  24. suanpanbutton.className = 'toolbutton';
  25. suanpanbutton.setAttribute('id','suanpan-button');
  26. suanpanbutton.setAttribute('title','Suanpan');
  27. suanpanbutton.onclick = function() {
  28. that.setAbacus(2);
  29. }
  30. var nepobutton = document.createElement('button');
  31. nepobutton.className = 'toolbutton';
  32. nepobutton.setAttribute('id','nepo-button');
  33. nepobutton.setAttribute('title','Nepohualtzintzin');
  34. nepobutton.onclick = function() {
  35. that.setAbacus(3);
  36. }
  37. var hexbutton = document.createElement('button');
  38. hexbutton.className = 'toolbutton';
  39. hexbutton.setAttribute('id','hex-button');
  40. hexbutton.setAttribute('title','Hexadecimal');
  41. hexbutton.onclick = function() {
  42. that.setAbacus(4);
  43. }
  44. var binarybutton = document.createElement('button');
  45. binarybutton.className = 'toolbutton';
  46. binarybutton.setAttribute('id','binary-button');
  47. binarybutton.setAttribute('title','Binary');
  48. binarybutton.onclick = function() {
  49. that.setAbacus(5);
  50. }
  51. var schetybutton = document.createElement('button');
  52. schetybutton.className = 'toolbutton';
  53. schetybutton.setAttribute('id','schety-button');
  54. schetybutton.setAttribute('title','Schety');
  55. schetybutton.onclick = function() {
  56. that.setAbacus(6);
  57. }
  58. var fractionsbutton = document.createElement('button');
  59. fractionsbutton.className = 'toolbutton';
  60. fractionsbutton.setAttribute('id','fractions-button');
  61. fractionsbutton.setAttribute('title','Fractions');
  62. fractionsbutton.onclick = function() {
  63. that.setAbacus(7);
  64. }
  65. var caacupebutton = document.createElement('button');
  66. caacupebutton.className = 'toolbutton';
  67. caacupebutton.setAttribute('id','caacupe-button');
  68. caacupebutton.setAttribute('title','Caacupé');
  69. caacupebutton.onclick = function() {
  70. that.setAbacus(8);
  71. }
  72. var rodsbutton = document.createElement('button');
  73. rodsbutton.className = 'toolbutton';
  74. rodsbutton.setAttribute('id','rods-button');
  75. rodsbutton.setAttribute('title','Rods');
  76. rodsbutton.onclick = function() {
  77. that.setAbacus(9);
  78. }
  79. var custombutton = document.createElement('button');
  80. custombutton.className = 'toolbutton';
  81. custombutton.setAttribute('id','custom-button');
  82. custombutton.setAttribute('title','Custom');
  83. custombutton.onclick = function() {
  84. that.setAbacus(10);
  85. }
  86. this.setAbacus = function(state) {
  87. that.popDown();
  88. g.initAbacus(state);
  89. that.setUsed();
  90. }
  91. this.resetBackgroundCols = function(){
  92. decimalbutton.style.backgroundColor = "#C0C0C0";
  93. sorobanbutton.style.backgroundColor = "#C0C0C0";
  94. suanpanbutton.style.backgroundColor = "#C0C0C0";
  95. nepobutton.style.backgroundColor = "#C0C0C0";
  96. hexbutton.style.backgroundColor = "#C0C0C0";
  97. binarybutton.style.backgroundColor = "#C0C0C0";
  98. schetybutton.style.backgroundColor = "#C0C0C0";
  99. fractionsbutton.style.backgroundColor = "#C0C0C0";
  100. caacupebutton.style.backgroundColor = "#C0C0C0";
  101. rodsbutton.style.backgroundColor = "#C0C0C0";
  102. custombutton.style.backgroundColor = "#C0C0C0";
  103. }
  104. this.setUsed = function(){
  105. this.resetBackgroundCols();
  106. switch(game.abacustype) {
  107. case 0:
  108. decimalbutton.style.backgroundColor = "#808080";
  109. break;
  110. case 1:
  111. sorobanbutton.style.backgroundColor = "#808080";
  112. break;
  113. case 2:
  114. suanpanbutton.style.backgroundColor = "#808080";
  115. break;
  116. case 3:
  117. nepobutton.style.backgroundColor = "#808080";
  118. break;
  119. case 4:
  120. hexbutton.style.backgroundColor = "#808080";
  121. break;
  122. case 5:
  123. binarybutton.style.backgroundColor = "#808080";
  124. break;
  125. case 6:
  126. schetybutton.style.backgroundColor = "#808080";
  127. break;
  128. case 7:
  129. fractionsbutton.style.backgroundColor = "#808080";
  130. break;
  131. case 8:
  132. caacupebutton.style.backgroundColor = "#808080";
  133. break;
  134. case 9:
  135. rodsbutton.style.backgroundColor = "#808080";
  136. break;
  137. case 10:
  138. custombutton.style.backgroundColor = "#808080";
  139. break;
  140. }
  141. }
  142. div.appendChild(decimalbutton);
  143. div.appendChild(sorobanbutton);
  144. div.appendChild(suanpanbutton);
  145. div.appendChild(nepobutton);
  146. div.appendChild(hexbutton);
  147. div.appendChild(binarybutton);
  148. div.appendChild(schetybutton);
  149. div.appendChild(fractionsbutton);
  150. div.appendChild(caacupebutton);
  151. div.appendChild(rodsbutton);
  152. div.appendChild(custombutton);
  153. this.setContent([div]);
  154. var that = this;
  155. var g = game;
  156. };
  157. var addEventListener = function (type, listener, useCapture) {
  158. return this.getPalette().addEventListener(type, listener, useCapture);
  159. };
  160. abacuspalette.AbacusPalette.prototype =
  161. Object.create(palette.Palette.prototype, {
  162. addEventListener: {
  163. value: addEventListener,
  164. enumerable: true,
  165. configurable: true,
  166. writable: true
  167. }
  168. });
  169. abacuspalette.AbacusPalette.prototype.setShared = function(state) {
  170. this.setShared(state);
  171. }
  172. return abacuspalette;
  173. });