mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-06-04 11:37:12 +08:00
Add scrolling via keyboard
This commit is contained in:
+12
-3
@@ -593,10 +593,16 @@
|
|||||||
switch(e.which) {
|
switch(e.which) {
|
||||||
case 38: // Up
|
case 38: // Up
|
||||||
case 87:
|
case 87:
|
||||||
|
if(Engine.activeModule == Outside){
|
||||||
|
Engine.activeModule.scrollSidebar('up');
|
||||||
|
}
|
||||||
Engine.log('up');
|
Engine.log('up');
|
||||||
break;
|
break;
|
||||||
case 40: // Down
|
case 40: // Down
|
||||||
case 83:
|
case 83:
|
||||||
|
if(Engine.activeModule == Outside){
|
||||||
|
Engine.activeModule.scrollSidebar('down');
|
||||||
|
}
|
||||||
Engine.log('down');
|
Engine.log('down');
|
||||||
break;
|
break;
|
||||||
case 37: // Left
|
case 37: // Left
|
||||||
@@ -605,17 +611,20 @@
|
|||||||
Engine.travelTo(Path);
|
Engine.travelTo(Path);
|
||||||
else if(Engine.activeModule == Path && Outside.tab)
|
else if(Engine.activeModule == Path && Outside.tab)
|
||||||
Engine.travelTo(Outside);
|
Engine.travelTo(Outside);
|
||||||
else if(Engine.activeModule == Outside && Room.tab)
|
else if(Engine.activeModule == Outside && Room.tab){
|
||||||
|
Engine.activeModule.scrollSidebar('left', true);
|
||||||
Engine.travelTo(Room);
|
Engine.travelTo(Room);
|
||||||
|
}
|
||||||
Engine.log('left');
|
Engine.log('left');
|
||||||
break;
|
break;
|
||||||
case 39: // Right
|
case 39: // Right
|
||||||
case 68:
|
case 68:
|
||||||
if(Engine.activeModule == Room && Outside.tab)
|
if(Engine.activeModule == Room && Outside.tab)
|
||||||
Engine.travelTo(Outside);
|
Engine.travelTo(Outside);
|
||||||
else if(Engine.activeModule == Outside && Path.tab)
|
else if(Engine.activeModule == Outside && Path.tab){
|
||||||
|
Engine.activeModule.scrollSidebar('right', true);
|
||||||
Engine.travelTo(Path);
|
Engine.travelTo(Path);
|
||||||
else if(Engine.activeModule == Path && Ship.tab)
|
}else if(Engine.activeModule == Path && Ship.tab)
|
||||||
Engine.travelTo(Ship);
|
Engine.travelTo(Ship);
|
||||||
Engine.log('right');
|
Engine.log('right');
|
||||||
break;
|
break;
|
||||||
|
|||||||
+59
-1
@@ -4,6 +4,7 @@
|
|||||||
var Outside = {
|
var Outside = {
|
||||||
name: _("Outside"),
|
name: _("Outside"),
|
||||||
|
|
||||||
|
_STORES_OFFSET: 0,
|
||||||
_GATHER_DELAY: 60,
|
_GATHER_DELAY: 60,
|
||||||
_TRAPS_DELAY: 90,
|
_TRAPS_DELAY: 90,
|
||||||
_POP_DELAY: [0.5, 3],
|
_POP_DELAY: [0.5, 3],
|
||||||
@@ -439,7 +440,7 @@ var Outside = {
|
|||||||
this.setTitle();
|
this.setTitle();
|
||||||
|
|
||||||
if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
|
if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
|
||||||
$('#storesContainer').css({top: village.height() + 26 + 'px'});
|
$('#storesContainer').css({top: village.height() + 26 + Outside._STORES_OFFSET + 'px'});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -611,5 +612,62 @@ var Outside = {
|
|||||||
Outside.updateWorkersView();
|
Outside.updateWorkersView();
|
||||||
Outside.updateVillageIncome();
|
Outside.updateVillageIncome();
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollSidebar: function(direction, reset) {
|
||||||
|
|
||||||
|
if( typeof reset != "undefined" ){
|
||||||
|
$('#village').css('top', '0px');
|
||||||
|
$('#storesContainer').css('top', '224px');
|
||||||
|
Outside._STORES_OFFSET = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var momentum = 10;
|
||||||
|
|
||||||
|
// If they hit up, we scroll everything down
|
||||||
|
if( direction == 'up' )
|
||||||
|
momentum = momentum * -1;
|
||||||
|
|
||||||
|
/* Let's stop scrolling if the top or bottom bound is in the viewport, based on direction */
|
||||||
|
if( direction == 'down' && inView( direction, $('#village') ) ){
|
||||||
|
console.log(direction);
|
||||||
|
console.log('IN VIEW');
|
||||||
|
return false;
|
||||||
|
}else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){
|
||||||
|
console.log(direction);
|
||||||
|
console.log('IN VIEW');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollByX( $('#village'), momentum );
|
||||||
|
scrollByX( $('#storesContainer'), momentum );
|
||||||
|
Outside._STORES_OFFSET += momentum;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
function inView(dir, elem){
|
||||||
|
|
||||||
|
var scTop = $('#main').offset().top;
|
||||||
|
var scBot = scTop + $('#main').height();
|
||||||
|
|
||||||
|
var elTop = elem.offset().top;
|
||||||
|
var elBot = elTop + elem.height();
|
||||||
|
|
||||||
|
if( dir == 'up' ){
|
||||||
|
// STOP MOVING IF BOTTOM OF ELEMENT IS VISIBLE IN SCREEN
|
||||||
|
return ( elBot < scBot );
|
||||||
|
}else if( dir == 'down' ){
|
||||||
|
return ( elTop > scTop );
|
||||||
|
}else{
|
||||||
|
return ( ( elBot <= scBot ) && ( elTop >= scTop ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollByX(elem, x){
|
||||||
|
|
||||||
|
var elTop = parseInt( elem.css('top'), 10 );
|
||||||
|
elem.css( 'top', ( elTop + x ) + "px" );
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user