Move movement functions to Engine. Create scrollable Path sidebar

This commit is contained in:
Travis Weston
2015-02-07 14:00:32 -05:00
parent 3d00ed3c40
commit 2d3daa572d
3 changed files with 72 additions and 37 deletions
+36 -6
View File
@@ -593,14 +593,14 @@
switch(e.which) { switch(e.which) {
case 38: // Up case 38: // Up
case 87: case 87:
if(Engine.activeModule == Outside){ if(Engine.activeModule == Outside || Engine.activeModule == Path)
Engine.activeModule.scrollSidebar('up'); 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){ if(Engine.activeModule == Outside || Engine.activeModule == Path){
Engine.activeModule.scrollSidebar('down'); Engine.activeModule.scrollSidebar('down');
} }
Engine.log('down'); Engine.log('down');
@@ -609,9 +609,10 @@
case 65: case 65:
if(Engine.activeModule == Ship && Path.tab) if(Engine.activeModule == Ship && Path.tab)
Engine.travelTo(Path); Engine.travelTo(Path);
else if(Engine.activeModule == Path && Outside.tab) else if(Engine.activeModule == Path && Outside.tab){
Engine.activeModule.scrollSidebar('left', true);
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.activeModule.scrollSidebar('left', true);
Engine.travelTo(Room); Engine.travelTo(Room);
} }
@@ -624,8 +625,10 @@
else if(Engine.activeModule == Outside && Path.tab){ else if(Engine.activeModule == Outside && Path.tab){
Engine.activeModule.scrollSidebar('right', true); 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.activeModule.scrollSidebar('right', true);
Engine.travelTo(Ship); Engine.travelTo(Ship);
}
Engine.log('right'); Engine.log('right');
break; break;
} }
@@ -703,6 +706,33 @@
})(); })();
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" );
}
//create jQuery Callbacks() to handle object events //create jQuery Callbacks() to handle object events
$.Dispatch = function( id ) { $.Dispatch = function( id ) {
var callbacks, topic = id && Engine.topics[ id ]; var callbacks, topic = id && Engine.topics[ id ];
+4 -29
View File
@@ -631,13 +631,13 @@ var Outside = {
/* Let's stop scrolling if the top or bottom bound is in the viewport, based on direction */ /* Let's stop scrolling if the top or bottom bound is in the viewport, based on direction */
if( direction == 'down' && inView( direction, $('#village') ) ){ if( direction == 'down' && inView( direction, $('#village') ) ){
console.log(direction);
console.log('IN VIEW');
return false; return false;
}else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){ }else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){
console.log(direction);
console.log('IN VIEW');
return false; return false;
} }
scrollByX( $('#village'), momentum ); scrollByX( $('#village'), momentum );
@@ -646,28 +646,3 @@ var Outside = {
} }
}; };
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" );
}
+32 -2
View File
@@ -1,7 +1,7 @@
var Path = { var Path = {
DEFAULT_BAG_SPACE: 10, DEFAULT_BAG_SPACE: 10,
_STORES_OFFSET: 0,
// Everything not in this list weighs 1 // Everything not in this list weighs 1
Weight: { Weight: {
'bone spear': 2, 'bone spear': 2,
@@ -116,7 +116,7 @@ var Path = {
} }
if(!ignoreStores && Engine.activeModule === Path) { if(!ignoreStores && Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'}); $('#storesContainer').css({top: perks.height() + 26 + Path._STORES_OFFSET + 'px'});
} }
} }
}, },
@@ -313,5 +313,35 @@ var Path = {
if(e.category == 'character' && e.stateName.indexOf('character.perks') == 0 && Engine.activeModule == Path){ if(e.category == 'character' && e.stateName.indexOf('character.perks') == 0 && Engine.activeModule == Path){
Path.updatePerks(); Path.updatePerks();
}; };
},
scrollSidebar: function(direction, reset){
if( typeof reset != "undefined" ){
$('#perks').css('top', '0px');
$('#storesContainer').css('top', '206px');
Path._STORES_OFFSET = 0;
return;
}
var momentum = 10;
if( direction == 'up' )
momentum = momentum * -1
if( direction == 'down' && inView( direction, $('#perks') ) ){
return false;
}else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){
return false;
}
scrollByX( $('#perks'), momentum );
scrollByX( $('#storesContainer'), momentum );
Path._STORES_OFFSET += momentum;
} }
}; };