From 690c8be1fb6414f0d9433acde2faff8a65f9d70c Mon Sep 17 00:00:00 2001 From: Robert Chen Date: Sun, 1 Dec 2013 05:24:08 -0800 Subject: [PATCH] Scrolling logbook --- js/main.js | 4 ++-- js/ui.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/js/main.js b/js/main.js index d8897d1..8481f22 100755 --- a/js/main.js +++ b/js/main.js @@ -356,7 +356,7 @@ function GameUI( canvasElem, gameState ){ var textContent = new createjs.Text( "", "20px Arial", "white" ); textContent.x = 750; textContent.y = 30; - this.stage.addChild( textContent); + //this.stage.addChild( textContent); var overlay = new createjs.Shape(); overlay.graphics.beginFill("#fffffff").drawRect(0, 0, 800, 600 ); overlay.alpha = 0; @@ -374,7 +374,7 @@ function GameUI( canvasElem, gameState ){ this.actuallySwitchScreen = function( screenName ){ that.stage.removeAllChildren(); that.activeScreenObj = new that.screens[ screenName ]( that.stage, gameState ); - that.stage.addChild( textContent ); + //that.stage.addChild( textContent ); that.stage.addChild( overlay ); dialogManager.render(); }; diff --git a/js/ui.js b/js/ui.js index 627361b..57a985c 100755 --- a/js/ui.js +++ b/js/ui.js @@ -269,6 +269,10 @@ function CookbookUI( stage, gameState ){ var cookbookImg = new createjs.Bitmap("res/screens/KitchenScreen/Cookbook-Open.png"); var closeButton = new Button( stage, gameState, 710, 10, 100, 50, null, null, function(){that.hideCookbook();} ); + + var scrollUpBtn = new Button( stage, gameState, 710, 80, 100, 50, null, null, function(){that.scrollUp();} ); + var scrollDownBtn = new Button( stage, gameState, 710, 540, 100, 50, null, null, function(){that.scrollDown();} ); + var turkeyTypeText = new createjs.Text("", "18px Arial", "black" ); turkeyTypeText.x = 535; turkeyTypeText.y = 56; @@ -276,24 +280,63 @@ function CookbookUI( stage, gameState ){ var turkeyWeightText = new createjs.Text("", "18px Arial", "black" ); turkeyWeightText.x = 553; turkeyWeightText.y = 85; - + var hiddenEntries = []; var logEntries = []; + this.hideCookbook = function(){ stage.removeChild( closeButton ); stage.removeChild( cookbookImg ); + stage.removeChild( scrollUpBtn ); + stage.removeChild( scrollDownBtn ); stage.removeChild( turkeyTypeText ); - stage.removeChild(turkeyWeightText); + stage.removeChild( turkeyWeightText ); for( i in logEntries ){ stage.removeChild(logEntries[i]); } + + for( i in hiddenEntries ){ + stage.removeChild(hiddenEntries[i]); + } + that.showingCookbook = false; gameState.pubsub.publish("Play", "Close_Cookbook"); } + this.scrollDown = function(){ + + // move to hidden list + if( logEntries.length > 1 ){ + // Move all entries up by 50 pixels + for( i in logEntries ){ + logEntries[i].y -= 50; + } + var topEntry = logEntries.shift(); + topEntry.alpha = 0; + hiddenEntries.push( topEntry ); + } + } + + + this.scrollUp = function(){ + // pop and fill in top + if( hiddenEntries.length > 0 ){ + var topEntry = hiddenEntries.pop(); + topEntry.alpha = 1; + logEntries.unshift( topEntry ); + + // shift everything down by 50 pixels + for( i in logEntries ){ + logEntries[i].y += 50; + } + } + } + // Show core temperature this.showCookbook = function(){ if( !that.showingCookbook ){ + // TODO: So this object is actually persistent: we should not remove/add children, just hide stuff visually + logEntries = []; stage.addChild( cookbookImg ); stage.addChild( closeButton ); @@ -313,9 +356,13 @@ function CookbookUI( stage, gameState ){ logEntries.push(logLine); stage.addChild(logLine); } + stage.addChild(turkeyTypeText); stage.addChild(turkeyWeightText); + stage.addChild(scrollUpBtn); + stage.addChild(scrollDownBtn); + that.showingCookbook = true; } }