Skip to content
This repository was archived by the owner on Jun 19, 2018. It is now read-only.

Commit 1beed45

Browse files
committed
updates to add "ask" functionality
1 parent 3842832 commit 1beed45

17 files changed

+809
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.swp
22
test/lib/*
3+
.DS_Store
34

45
logs
56

img/ask-bottom.png

909 Bytes
Loading

img/ask-button.png

1.89 KB
Loading

img/playerStartFlag.png

-3.17 KB
Loading

js/Reporter.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var Reporter = function(data) {
1919
this.cmd = data.cmd;
2020
this.color = data.color;
2121
this.isDiscrete = data.isDiscrete;
22-
this.label = data.label;
2322
this.mode = data.mode;
2423
this.param = data.param;
2524
this.sliderMin = data.sliderMin;
@@ -35,11 +34,19 @@ var Reporter = function(data) {
3534
this.slider = null; // slider jQ element
3635
};
3736

37+
Reporter.prototype.determineReporterLabel = function() {
38+
if (this.target === 'Stage') {
39+
return this.param;
40+
} else {
41+
return this.target + ': ' + this.param;
42+
}
43+
}
44+
3845
Reporter.prototype.attach = function(scene) {
3946
switch (this.mode) {
4047
case 1: // Normal
4148
case 3: // Slider
42-
this.el = $('<div class="reporter-normal">' + this.label + '</div>');
49+
this.el = $('<div class="reporter-normal">' + this.determineReporterLabel() + '</div>');
4350
this.valueEl = $('<div class="reporter-inset">null</div>');
4451
this.el.append(this.valueEl);
4552
if (this.mode == 3) {

js/Sprite.js

+59-11
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ var Sprite = function(data) {
7373
this.talkBubbleStyler = null;
7474
this.talkBubbleOn = false;
7575

76+
// HTML element for the ask bubbles
77+
this.askInput = null;
78+
this.askInputField = null;
79+
this.askInputButton = null;
80+
this.askInputOn = false;
81+
7682
// Internal variables used for rendering meshes.
83+
this.askAnswer = null; //this is a private variable
7784
this.textures = [];
7885
this.materials = [];
7986
this.geometries = [];
@@ -142,14 +149,26 @@ Sprite.prototype.attach = function(scene) {
142149
this.updateVisible();
143150
this.updateTransform();
144151

145-
this.talkBubble = $('<div class="bubble-container"></div>');
146-
this.talkBubble.css('display', 'none');
147-
this.talkBubbleBox = $('<div class="bubble"></div>');
148-
this.talkBubbleStyler = $('<div class="bubble-say"></div>');
149-
this.talkBubble.append(this.talkBubbleBox);
150-
this.talkBubble.append(this.talkBubbleStyler);
152+
if (! this.isStage) {
153+
this.talkBubble = $('<div class="bubble-container"></div>');
154+
this.talkBubble.css('display', 'none');
155+
this.talkBubbleBox = $('<div class="bubble"></div>');
156+
this.talkBubbleStyler = $('<div class="bubble-say"></div>');
157+
this.talkBubble.append(this.talkBubbleBox);
158+
this.talkBubble.append(this.talkBubbleStyler);
159+
}
160+
161+
this.askInput = $('<div class="ask-container"></div>');
162+
this.askInput.css('display', 'none');
163+
this.askInputField = $('<div class="ask-field"></div>');
164+
this.askInputTextField = $('<input class="ask-text-field"></input>');
165+
this.askInputField.append(this.askInputTextField);
166+
this.askInputButton = $('<div class="ask-button"></div>');
167+
this.askInput.append(this.askInputField);
168+
this.askInput.append(this.askInputButton);
151169

152170
runtime.scene.append(this.talkBubble);
171+
runtime.scene.append(this.askInput);
153172
};
154173

155174
// Load sounds from the server and buffer them
@@ -254,20 +273,22 @@ Sprite.prototype.onClick = function(evt) {
254273
};
255274

256275
Sprite.prototype.setVisible = function(v) {
276+
if (v === true || v === false) {
257277
this.visible = v;
258278
this.updateVisible();
279+
}
259280
};
260281

261282
Sprite.prototype.updateLayer = function() {
262283
$(this.mesh).css('z-index', this.z);
263-
if (this.talkBubble) this.talkBubble.css('z-index', this.z);
284+
if (this.talkBubble) $(this.talkBubble).css('z-index', this.z);
285+
if (this.askInput) this.askInput.css('z-index', this.z);
264286
};
265287

266288
Sprite.prototype.updateVisible = function() {
267289
$(this.mesh).css('display', this.visible ? 'inline' : 'none');
268-
if (this.talkBubbleOn) {
269-
this.talkBubble.css('display', this.visible ? 'inline-block' : 'none');
270-
}
290+
if (this.talkBubbleOn) this.talkBubble.css('display', this.visible ? 'inline-block' : 'none');
291+
if (this.askInputOn) this.askInput.css('display', this.visible ? 'inline-block' : 'none');
271292
};
272293

273294
Sprite.prototype.updateTransform = function() {
@@ -347,13 +368,21 @@ Sprite.prototype.showBubble = function(text, type) {
347368
this.talkBubble.css('left', xy[0] + 'px');
348369
this.talkBubble.css('top', xy[1] + 'px');
349370

350-
371+
this.talkBubble.removeClass('say-think-border');
372+
this.talkBubble.removeClass('ask-border');
373+
351374
this.talkBubbleStyler.removeClass('bubble-say');
352375
this.talkBubbleStyler.removeClass('bubble-think');
376+
this.talkBubbleStyler.removeClass('bubble-ask');
353377
if (type == 'say') {
378+
this.talkBubbleBox.addClass('say-think-border');
354379
this.talkBubbleStyler.addClass('bubble-say');
355380
} else if (type == 'think') {
381+
this.talkBubbleBox.addClass('say-think-border');
356382
this.talkBubbleStyler.addClass('bubble-think');
383+
} else if (type == 'doAsk') {
384+
this.talkBubbleBox.addClass('ask-border');
385+
this.talkBubbleStyler.addClass('bubble-ask');
357386
}
358387

359388
if (this.visible) {
@@ -367,6 +396,25 @@ Sprite.prototype.hideBubble = function() {
367396
this.talkBubble.css('display', 'none');
368397
};
369398

399+
Sprite.prototype.showAsk = function() {
400+
this.askInputOn = true;
401+
this.askInput.css('z-index', this.z);
402+
this.askInput.css('left', '15px');
403+
this.askInput.css('right', '15px');
404+
this.askInput.css('bottom', '7px');
405+
this.askInput.css('height', '25px');
406+
407+
if (this.visible) {
408+
this.askInput.css('display', 'inline-block');
409+
this.askInputTextField.focus();
410+
}
411+
};
412+
413+
Sprite.prototype.hideAsk = function() {
414+
this.askInputOn = false;
415+
this.askInput.css('display', 'none');
416+
};
417+
370418
Sprite.prototype.setXY = function(x, y) {
371419
this.scratchX = x;
372420
this.scratchY = y;

js/Stage.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Stage = function(data) {
3333
this.lineCanvas.width = 480;
3434
this.lineCanvas.height = 360;
3535
this.lineCache = this.lineCanvas.getContext('2d');
36+
this.isStage = true;
3637

3738
Sprite.call(this, data);
3839
};

js/primitives/LooksPrims.js

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ LooksPrims.prototype.addPrimsTo = function(primTable) {
4343
primTable['setGraphicEffect:to:'] = this.primSetEffect;
4444
primTable['filterReset'] = this.primClearEffects;
4545

46+
primTable['doAsk'] = this.primDoAsk;
47+
primTable['answer'] = this.primAnswer;
48+
4649
primTable['say:'] = function(b) { showBubble(b, 'say'); };
4750
primTable['say:duration:elapsed:from:'] = function(b) { showBubbleAndWait(b, 'say'); };
4851
primTable['think:'] = function(b) { showBubble(b, 'think'); };
@@ -170,6 +173,17 @@ LooksPrims.prototype.primClearEffects = function(b) {
170173
s.updateFilters();
171174
};
172175

176+
LooksPrims.prototype.primDoAsk= function(b) {
177+
showBubble(b, "doAsk");
178+
var s = interp.targetSprite();
179+
if (s != null) s.showAsk();
180+
};
181+
182+
LooksPrims.prototype.primAnswer = function() {
183+
var s = interp.targetSprite();
184+
return ((s != null) ? s.answer : undefined);
185+
};
186+
173187
var showBubble = function(b, type) {
174188
var s = interp.targetSprite();
175189
if (s != null) s.showBubble(interp.arg(b, 0), type);

player.css

+45-2
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ button#trigger-stop:hover {
398398
}
399399

400400
/* Say/think bubble styles */
401-
.bubble-container {
401+
.bubble-container {
402402
position: absolute;
403403
}
404404
.bubble {
@@ -407,7 +407,6 @@ button#trigger-stop:hover {
407407
max-width: 120px;
408408
min-width: 40px;
409409
padding: 6px 11px 6px 11px;
410-
border: 3px solid rgb(160, 160, 160);
411410
border-radius: 10px;
412411
background: #fff;
413412
font-family: sans-serif;
@@ -416,6 +415,20 @@ button#trigger-stop:hover {
416415
color: #000;
417416
text-align: center;
418417
}
418+
.bubble.say-think-border {
419+
border: 3px solid rgb(160, 160, 160);
420+
}
421+
.bubble.ask-border, .ask-container {
422+
border: 3px solid rgb(74, 173, 222);
423+
}
424+
.bubble-ask {
425+
position: absolute;
426+
margin-top: -3px;
427+
margin-left: 8px;
428+
width: 44px;
429+
height: 18px;
430+
background: url(img/ask-bottom.png) transparent no-repeat;
431+
}
419432
.bubble-say {
420433
position: absolute;
421434
margin-top: -3px;
@@ -432,3 +445,33 @@ button#trigger-stop:hover {
432445
height: 19px;
433446
background: url(img/think-bottom.png) transparent no-repeat;
434447
}
448+
.ask-container {
449+
position: absolute;
450+
display: inline-block;
451+
padding: 5px 0px 0px 5px;
452+
border-radius: 5px;
453+
background: #fff;
454+
font-family: sans-serif;
455+
font-weight: bold;
456+
font-size: 14px;
457+
color: #000;
458+
}
459+
.ask-container .ask-field .ask-text-field {
460+
width: 405px;
461+
height: 16px;
462+
font-family: sans-serif;
463+
font-weight: light;
464+
font-size: 12px;
465+
background: #EAEAEA;
466+
}
467+
468+
.ask-container .ask-button {
469+
position: absolute;
470+
right: 2px;
471+
top: 2px;
472+
width: 25px;
473+
height: 25px;
474+
background: url(img/ask-button.png) transparent no-repeat;
475+
}
476+
477+

test/artifacts/IOMock.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var ioMock = function() {
4+
var args = createArgs(arguments);
5+
6+
function getArgs(argKey) {
7+
return ((argKey in args) ? args[argKey] : null);
8+
}
9+
10+
function createArgs(methodArgs) {
11+
var args = {};
12+
if (methodArgs.length) {
13+
_.each(methodArgs, function(newObject) {
14+
_.each(newObject, function(value, key) {
15+
args[key] = value;
16+
});
17+
});
18+
}
19+
return args;
20+
}
21+
22+
return {
23+
'getCount' : function() { return getArgs('getCount'); }
24+
}
25+
};

test/artifacts/TargetMock.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
var targetMock = function() {
44
return {
5-
'showBubble' : function() {}
5+
'showBubble' : function() {},
6+
'showAsk' : function() {},
7+
'answer' : 22
68
};
79

810
}

test/artifacts/ask-artifact.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
'use strict';
2-
31
var sensingData = {
42
"objName": "Stage",
3+
"variables": [{
4+
"name": "myAnswer",
5+
"value": 0,
6+
"isPersistent": false
7+
}],
58
"costumes": [{
69
"costumeName": "backdrop1",
710
"baseLayerID": -1,
@@ -16,6 +19,15 @@ var sensingData = {
1619
"videoAlpha": 0.5,
1720
"children": [{
1821
"objName": "Sprite1",
22+
"variables": [{
23+
"name": "myAnswer2",
24+
"value": 0,
25+
"isPersistent": false
26+
}, {
27+
"name": "answer",
28+
"value": 0,
29+
"isPersistent": false
30+
}],
1931
"scripts": [[42, 40.5, [["whenGreenFlag"], ["doAsk", "What's your name?"]]],
2032
[44.5,
2133
155.5,

0 commit comments

Comments
 (0)