123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- Blockly.Blocks['controls_if_better'] = {
-
- init: function() {
- this.setHelpUrl(Blockly.Msg.CONTROLS_IF_HELPURL);
- this.setColour(Blockly.Blocks.logic.HUE);
- this.appendValueInput('IF0')
- .setCheck('Boolean')
- .appendField(Blockly.Msg.CONTROLS_IF_MSG_IF);
- this.appendStatementInput('DO0')
- .appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.updateShape_();
-
- var thisBlock = this;
- this.setTooltip(function() {
- if (!thisBlock.elseifCount_ && !thisBlock.elseCount_) {
- return Blockly.Msg.CONTROLS_IF_TOOLTIP_1;
- } else if (!thisBlock.elseifCount_ && thisBlock.elseCount_) {
- return Blockly.Msg.CONTROLS_IF_TOOLTIP_2;
- } else if (thisBlock.elseifCount_ && !thisBlock.elseCount_) {
- return Blockly.Msg.CONTROLS_IF_TOOLTIP_3;
- } else if (thisBlock.elseifCount_ && thisBlock.elseCount_) {
- return Blockly.Msg.CONTROLS_IF_TOOLTIP_4;
- }
- return '';
- });
- this.elseifCount_ = 0;
- this.elseCount_ = 0;
- },
-
- mutationToDom: function() {
- if (!this.elseifCount_ && !this.elseCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.elseifCount_) {
- container.setAttribute('elseif', this.elseifCount_);
- }
- if (this.elseCount_) {
- container.setAttribute('else', 1);
- }
- return container;
- },
-
- domToMutation: function(xmlElement) {
- this.elseifCount_ = parseInt(xmlElement.getAttribute('elseif'), 10) || 0;
- this.elseCount_ = parseInt(xmlElement.getAttribute('else'), 10) || 0;
- this.updateShape_();
- },
-
-
-
-
-
- updateShape_: function() {
-
- if (this.getInput('ELSE')) {
- this.removeInput('ELSE');
- }
- var i = 1;
- while (this.getInput('IF' + i)) {
- this.removeInput('IF' + i);
- this.removeInput('DO' + i);
- i++;
- }
-
- for (var i = 1; i <= this.elseifCount_; i++) {
- this.appendValueInput('IF' + i)
- .setCheck('Boolean')
- .appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF);
- this.appendStatementInput('DO' + i)
- .appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);
- }
- if (this.elseCount_) {
- this.appendStatementInput('ELSE')
- .appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE);
- }
- }
- };
|