From a79117a647747fcbc4264697a501cbfbc0d24251 Mon Sep 17 00:00:00 2001 From: Terence Sun Date: Sat, 1 Jun 2013 15:41:50 -0700 Subject: [PATCH] Edited mouse handler so that dbclick is select for movement and click is select for info --- GameLayer/gamelayer.js | 75 ++++++++++++++++++++---------------------- GameLayer/ui.js | 18 ++++++++++ 2 files changed, 54 insertions(+), 39 deletions(-) diff --git a/GameLayer/gamelayer.js b/GameLayer/gamelayer.js index 43f9e29..e5a4439 100644 --- a/GameLayer/gamelayer.js +++ b/GameLayer/gamelayer.js @@ -194,12 +194,40 @@ function refresh(event) { // sList[i].survival(); // } // } + +function settMoveHandler(event){ + if (event.type == "dblclick" && event.nativeEvent.which === 1){ + if (focus == null){ + focus = event.target; + //console.log(focus); + aimSight(event.stageX, event.stageY); + sight.alpha = .5; + popAdjuster.alpha = 1; + updateUI(focus); + stage.addEventListener("stagemousemove", stageEventHandler); + stage.addEventListener("click", stageEventHandler); + } + } +} + function mouseHandler(event){ if (event.type == "click" && event.nativeEvent.which === 1){ + updateUI(event.target); + } +} + +function stageEventHandler(event){ + //console.log("stageevent called"); + if (event.type == "stagemousemove"){ + //console.log("stagemousemoved"); + var loc = stage.globalToLocal(event.stageX, event.stageY); + aimSight(loc.x, loc.y); + aimPopAdjuster(); + updatePopAdjuster(); + } + if (event.type == "click"){ if (focus != null){ - //console.log("Secondclicked"); - //console.log(focus.movingPop); - //console.log(sight.alpha); + // Moves the selected population on the second click if (focus.movingPop > 0){ //console.log("focus.movingPop > 0"); var loc = stage.globalToLocal(event.stageX, event.stageY); @@ -212,9 +240,9 @@ function mouseHandler(event){ focus.destinationX = loc.x; focus.destinationY = loc.y; } - } else { + } else { sight.alpha = 0; - popAdjuster.alpha = 0 + popAdjuster.alpha = 0; } // sight.alpha = 0; // popAdjuster.alpha = 0; @@ -223,45 +251,13 @@ function mouseHandler(event){ focus = null; // stage.removeEventListener('click', stageEventHandler); stage.removeEventListener('stagemousemove', stageEventHandler); + stage.removeEventListener('click', stageEventHandler); contentcontainer.children[1].removeAllChildren(); } else { - focus = event.target; - //console.log(focus); - aimSight(event.stageX, event.stageY); - sight.alpha = .5; - popAdjuster.alpha = 1; - //console.log(sight.alpha); - //console.log("first clicked"); - //console.log(focus); - currentName = new createjs.Text("Current Population", "24px Arial", "#000"); - currentName.x = 175; - currentName.y = 10; - contentcontainer.children[1].addChild(currentName); - - currentPop = new createjs.Text("Population size: " + focus.population, "12px Arial", "#000"); - currentPop.x = 10; - currentPop.y =50; - contentcontainer.children[1].addChild(currentPop); - - resist = new createjs.Text("Heat preference: " + focus.traits.list[0], "12px Arial", "#000"); - resist.x = 10; - resist.y = 100; - contentcontainer.children[1].addChild(resist); - stage.addEventListener("stagemousemove", stageEventHandler); + contentcontainer.children[1].removeAllChildren(); } } } - -function stageEventHandler(event){ - //console.log("stageevent called"); - if (event.type == "stagemousemove"){ - //console.log("stagemousemoved"); - var loc = stage.globalToLocal(event.stageX, event.stageY); - aimSight(loc.x, loc.y); - aimPopAdjuster(); - updatePopAdjuster(); - } -} // 0 = % heat pref // 1 = % water needy // 2 = % nutrient dependent @@ -282,6 +278,7 @@ function Settlement(pop, xCoord, yCoord, amap) { this.destinationY; this.speed; this.addEventListener("click", mouseHandler); + this.addEventListener("dblclick", settMoveHandler); this.color = rgbToHex(Math.floor(255*this.traits.list[0]),Math.floor(255*this.traits.list[1]),Math.floor(255*this.traits.list[2])) this.graphics.beginStroke("black").beginFill(this.color).drawCircle(0,0,8); console.log(this.color); diff --git a/GameLayer/ui.js b/GameLayer/ui.js index 13b097c..f340d02 100644 --- a/GameLayer/ui.js +++ b/GameLayer/ui.js @@ -26,4 +26,22 @@ function initUI(){ uiStage.addChild(contentcontainer); uiStage.update(); +} + +function updateUI(focus){ + contentcontainer.children[1].removeAllChildren(); + currentName = new createjs.Text("Current Population", "24px Arial", "#000"); + currentName.x = 175; + currentName.y = 10; + contentcontainer.children[1].addChild(currentName); + + currentPop = new createjs.Text("Population size: " + focus.population, "12px Arial", "#000"); + currentPop.x = 10; + currentPop.y =50; + contentcontainer.children[1].addChild(currentPop); + + resist = new createjs.Text("Heat preference: " + focus.traits.list[0], "12px Arial", "#000"); + resist.x = 10; + resist.y = 100; + contentcontainer.children[1].addChild(resist); } \ No newline at end of file