Merge pull request #25 from toofarapart/persistent_stores_view

Stores panel now persists on all non-world/non-space views.
This commit is contained in:
Michael Townsend
2013-07-08 14:25:20 -07:00
6 changed files with 72 additions and 7 deletions
+46 -3
View File
@@ -289,15 +289,35 @@ var Engine = {
travelTo: function(module) {
if(Engine.activeModule != module) {
var currentIndex = Engine.activeModule ? $('.location').index(Engine.activeModule.panel) : 1;
Engine.activeModule = module;
$('div.headerButton').removeClass('selected');
module.tab.addClass('selected');
var slider = $('#locationSlider');
var stores = $('#storesContainer');
var panelIndex = $('.location').index(module.panel);
var diff = Math.abs(panelIndex - currentIndex);
slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff);
module.onArrival();
if(Engine.storeAvailable('wood')) {
// FIXME Why does this work if there's an animation queue...?
stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff);
}
module.onArrival(diff);
if(Engine.activeModule == Room || Engine.activeModule == Path) {
// Don't fade out the weapons if we're switching to a module
// where we're going to keep showing them anyway.
if (module != Room && module != Path) {
$('div#weapons').animate({opacity: 0}, 300);
}
}
if(module == Room || module == Path) {
$('div#weapons').animate({opacity: 1}, 300);
}
Engine.activeModule = module;
Notifications.printQueue(module);
}
@@ -500,6 +520,29 @@ var Engine = {
});
Room.updateIncomeView();
},
// Move the stores panel beneath top_container (or to top: 0px if top_container
// either hasn't been filled in or is null) using transition_diff to sync with
// the animation in Engine.travelTo().
moveStoresView: function(top_container, transition_diff) {
var stores = $('#storesContainer');
// If we don't have a storesContainer yet, leave.
if(typeof(stores) === 'undefined') return;
if(typeof(transition_diff) === 'undefined') transition_diff = 1;
if(top_container === null) {
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
}
else if(!top_container.length) {
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
}
else {
stores.animate({top: top_container.height() + 26 + 'px'},
{queue: false, duration: 300 * transition_diff});
}
},
num: function(name, craftable) {
switch(craftable.type) {
+8 -1
View File
@@ -461,6 +461,10 @@ var Outside = {
}
this.setTitle();
if(Engine.activeModule === Outside && village.children().length > 1) {
$('#storesContainer').css({top: village.height() + 26 + 'px'});
}
},
checkWorker: function(name) {
@@ -565,13 +569,16 @@ var Outside = {
$('#location_outside').text(title);
},
onArrival: function() {
onArrival: function(transition_diff) {
Outside.setTitle();
if(!State.seenForest) {
Notifications.notify(Outside, "the sky is grey and the wind blows relentlessly");
State.seenForest = true;
}
Outside.updateTrapButton();
Outside.updateVillage();
Engine.moveStoresView($('#village'), transition_diff);
},
gatherWood: function() {
+7 -1
View File
@@ -106,6 +106,10 @@ var Path = {
perks.appendTo(Path.panel);
}
}
if(Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
}
},
updateOutfitting: function() {
@@ -268,10 +272,12 @@ var Path = {
}
},
onArrival: function() {
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks();
Engine.moveStoresView($('#perks'), transition_diff);
},
setTitle: function() {
+7 -1
View File
@@ -502,7 +502,7 @@ var Room = {
options: {}, // Nothing for now
onArrival: function() {
onArrival: function(transition_diff) {
Room.setTitle();
if(Room.changed) {
Notifications.notify(Room, "the fire is " + State.room.fire.text);
@@ -518,6 +518,8 @@ var Room = {
Room.updateIncomeView();
Notifications.notify(Room, "the stranger is standing by the fire. she says she can help. says she builds things.")
}
Engine.moveStoresView(null, transition_diff);
},
TempEnum: {
@@ -793,6 +795,10 @@ var Room = {
if(newRow) {
Room.updateIncomeView();
}
if($("div#outsidePanel").length) {
Outside.updateVillage();
}
},
updateIncomeView: function() {
+3 -1
View File
@@ -81,13 +81,15 @@ var Ship = {
options: {}, // Nothing for now
onArrival: function() {
onArrival: function(transition_diff) {
Ship.setTitle();
if(!State.seenShip) {
Notifications.notify(Ship, 'somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.');
State.seenShip = true;
Engine.saveGame();
}
Engine.moveStoresView(null, transition_diff);
},
setTitle: function() {
+1
View File
@@ -757,6 +757,7 @@ var World = {
$('#outerSlider').animate({opacity: '0'}, 600, 'linear', function() {
$('#outerSlider').css('left', '0px');
$('#locationSlider').css('left', '0px');
$('#storesContainer').css({'top': '0px', 'right': '0px'});
Engine.activeModule = Room;
$('div.headerButton').removeClass('selected');
Room.tab.addClass('selected');