Skip to content

Commit

Permalink
Added max/zero buttons to worker assignment and expedition supply pac…
Browse files Browse the repository at this point in the history
…king to prevent eg having to click 50x to fill food supplies.
  • Loading branch information
Zarkonnen committed Jul 4, 2013
1 parent 9327358 commit 6d99cb7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
45 changes: 33 additions & 12 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,34 @@ div.button div.cooldown {

/* Up/Down buttons. They're complicated! */

.upBtn, .dnBtn {
.upBtn, .dnBtn, .maxBtn, .zeroBtn {
position: absolute;
width: 14px;
height: 15px;
right: 0px;
cursor: pointer;
}

.upBtn.disabled, .dnBtn.disabled {
.upBtn, .dnBtn {
right: 0px;
}

.maxBtn, .zeroBtn {
right: -11px;
}

.upBtn.disabled, .dnBtn.disabled, .maxBtn.disabled, .zeroBtn.disabled {
cursor: default;
}

.upBtn {
top: -2px;
}

.upBtn:after, .upBtn:before {
.maxBtn {
top: -2px;
}

.upBtn:after, .upBtn:before, .maxBtn:after, .maxBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
Expand All @@ -219,15 +230,15 @@ div.button div.cooldown {
bottom: 4px;
}

.upBtn:after {
.upBtn:after, .maxBtn:after {
border-color: transparent transparent white;
}

.upBtn:before {
.upBtn:before, .maxBtn:before {
border-color: transparent transparent black;
}

.upBtn.disabled:before {
.upBtn.disabled:before, .maxBtn.disabled:before {
border-color: transparent transparent #999;
}

Expand All @@ -236,7 +247,11 @@ div.button div.cooldown {
bottom: -3px;
}

.dnBtn:after, .dnBtn:before {
.zeroBtn {
bottom: -3px;
}

.dnBtn:after, .dnBtn:before, .zeroBtn:after, .zeroBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
Expand All @@ -251,21 +266,27 @@ div.button div.cooldown {
margin-left: -3px;
}

.upBtn:before, .dnBtn:before {
.upBtn:before, .dnBtn:before, .maxBtn:before, .zeroBtn:before {
border-width: 5px;
left: 50%;
margin-left: -5px;
}

.dnBtn:after {
.maxBtn:after, .zeroBtn:after {
border-width: 2px;
left: 50%;
margin-left: -2px;
}

.dnBtn:after, .zeroBtn:after {
border-color: white transparent transparent;
}

.dnBtn:before {
.dnBtn:before, .zeroBtn:before {
border-color: black transparent transparent;
}

.dnBtn.disabled:before {
.dnBtn.disabled:before, .zeroBtn.disabled:before {
border-color: #999 transparent transparent;
}

Expand Down
26 changes: 26 additions & 0 deletions script/outside.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ var Outside = {
numGatherers -= State.outside.workers[k];
if(State.outside.workers[k] == 0) {
$('.dnBtn', row).addClass('disabled');
$('.zeroBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.zeroBtn', row).removeClass('disabled');
}
}

Expand All @@ -310,8 +312,10 @@ var Outside = {

if(numGatherers == 0) {
$('.upBtn', '#workers').addClass('disabled');
$('.maxBtn', '#workers').addClass('disabled');
} else {
$('.upBtn', '#workers').removeClass('disabled');
$('.maxBtn', '#workers').removeClass('disabled');
}


Expand All @@ -338,8 +342,10 @@ var Outside = {
$('<span>').text(num).appendTo(val);

if(name != 'gatherer') {
$('<div>').addClass('maxBtn').appendTo(val).click(Outside.maxWorker);
$('<div>').addClass('upBtn').appendTo(val).click(Outside.increaseWorker);
$('<div>').addClass('dnBtn').appendTo(val).click(Outside.decreaseWorker);
$('<div>').addClass('zeroBtn').appendTo(val).click(Outside.zeroWorker);
}

$('<div>').addClass('clear').appendTo(row);
Expand Down Expand Up @@ -376,6 +382,26 @@ var Outside = {
}
},

maxWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(Outside.getNumGatherers() > 0) {
Engine.log('maxing ' + worker);
State.outside.workers[worker] += Outside.getNumGatherers();
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
},

zeroWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(State.outside.workers[worker] > 0) {
Engine.log('zeroing ' + worker);
State.outside.workers[worker] = 0;
Outside.updateVillageIncome();
Outside.updateWorkersView();
}
},

updateVillageRow: function(name, num, village) {
var id = 'building_row_' + name.replace(' ', '-');
var row = $('div#' + id, village);
Expand Down
30 changes: 30 additions & 0 deletions script/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,17 @@ var Path = {
}
if(num == 0) {
$('.dnBtn', row).addClass('disabled');
$('.zeroBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.zeroBtn', row).removeClass('disabled');
}
if(num >= numAvailable || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.maxBtn', row).addClass('disabled');
} else if(space >= Path.getWeight(k)) {
$('.upBtn', row).removeClass('disabled');
$('.maxBtn', row).removeClass('disabled');
}
} else if(have == 0 && row.length > 0) {
row.remove();
Expand All @@ -225,6 +229,8 @@ var Path = {
$('<span>').text(num).appendTo(val);
$('<div>').addClass('upBtn').appendTo(val).click(Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click(Path.decreaseSupply);
$('<div>').addClass('maxBtn').appendTo(val).click(Path.maxSupply);
$('<div>').addClass('zeroBtn').appendTo(val).click(Path.zeroSupply);
$('<div>').addClass('clear').appendTo(row);

var numAvailable = Engine.getStore(name);
Expand Down Expand Up @@ -259,6 +265,30 @@ var Path = {
}
},

maxSupply: function() {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('maxing ' + supply);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(Path.getFreeSpace() >= Path.getWeight(supply) && cur < Engine.getStore(supply)) {
var maxExtraByWeight = Math.floor(Path.getFreeSpace() / Path.getWeight(supply));
var maxExtraByStore = Engine.getStore(supply) - cur;
Path.outfit[supply] = cur + Math.min(maxExtraByWeight, maxExtraByStore);
Path.updateOutfitting();
}
},

zeroSupply: function() {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('zeroing ' + supply);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(cur > 0) {
Path.outfit[supply] = 0;
Path.updateOutfitting();
}
},

onArrival: function() {
Path.setTitle();
Path.updateOutfitting();
Expand Down

0 comments on commit 6d99cb7

Please sign in to comment.