More comprehensive changes, UI tweaking

This commit is contained in:
Colin McLeod
2015-05-03 13:23:30 -07:00
parent 71405e6cb7
commit 022836bde1
29 changed files with 339 additions and 374 deletions

View File

@@ -13,7 +13,7 @@ angular.module('app').config(['$provide','$stateProvider', '$urlRouterProvider',
params: {
// TODO: Squash:false not working due to UI-router issue
shipId: { value: 'sidewinder', squash: false}, // Allow 'shipId' parameter to default to
code: { value: undefined, squash: true } // Allow 'code' parameter to be empty/optional
code: { value: null, squash: true } // Allow 'code' parameter to be empty/optional
},
templateUrl: 'views/page-outfit.html',
controller: 'OutfitController',

View File

@@ -1,29 +1,32 @@
angular.module('app')
.controller('ErrorController', ['$rootScope','$scope','$stateParams', '$location', function ($rootScope, $scope, $p, $location) {
.controller('ErrorController', ['$window','$rootScope','$scope','$stateParams', '$location', function ($window, $rootScope, $scope, $p, $location) {
$rootScope.title = 'Error';
$scope.path = $location.path();
$scope.type = $p.type || 'unknown';
$scope.browser = $window.navigator.appVersion;
switch ($scope.type) {
case 404:
$scope.msgPre = 'Page';
$scope.msgHighlight = $scope.path;
$scope.msgPost = 'Not Found';
$scope.image = 'deep-space';
$rootScope.bodyClass = 'deep-space';
break;
case 'no-ship':
$scope.msgPre = 'Ship';
$scope.msgHighlight = $p.message;
$scope.msgPost = 'does not exist';
$scope.image = 'thargoid';
$rootScope.bodyClass = 'docking-bay';
break;
case 'build-fail':
$scope.msgPre = 'Build Failure!';
$scope.image = 'ship-explode';
$rootScope.bodyClass = 'docking-bay';
break;
default:
$scope.msgPre = "Uh, this is bad..";
$scope.image = 'thargoid';
$rootScope.bodyClass = null;
}
}]);

View File

@@ -11,7 +11,6 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s
}
$scope.buildName = $p.bn;
$rootScope.title = ship.name + ($scope.buildName? ' - ' + $scope.buildName: '');
$scope.ship = ship;
$scope.pp = ship.common[0]; // Power Plant
$scope.th = ship.common[1]; // Thruster
@@ -25,6 +24,8 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s
$scope.availCS = Components.forShip(ship.id);
$scope.selectedSlot = null;
$scope.savedCode = Persist.getBuild(ship.id, $scope.buildName);
$rootScope.title = ship.name + ($scope.buildName? ' - ' + $scope.buildName: '');
$rootScope.bodyClass = 'docking-bay';
// for debugging
window.myScope = $scope;
@@ -62,7 +63,7 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s
} else if (type == 'i') {
ship.use(slot, e.srcElement.id, Components.internal(e.srcElement.id));
} else if (type == 'b') {
ship.useBulkhead(slot, e.srcElement.id);
ship.useBulkhead(e.srcElement.id);
} else {
ship.use(slot, null, null);
}
@@ -88,9 +89,11 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s
* for this ship & with the exact name.
*/
$scope.saveBuild = function() {
if($scope.code != $scope.savedCode) {
if($scope.buildName && $scope.code != $scope.savedCode) {
Persist.saveBuild(ship.id, $scope.buildName, $scope.code);
$scope.savedCode = $scope.code;
// Edge case TODO: comment more
$state.go('outfit', {shipId: ship.id, code: $scope.savedCode, bn: $scope.buildName}, {location:'replace', notify:false});
}
}
@@ -104,6 +107,10 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s
$state.go('outfit', {shipId: ship.id, code: null, bn: null}, {location:'replace', reload:true});
}
$scope.bnChange = function(){
$scope.savedCode = Persist.getBuild(ship.id, $scope.buildName);
}
$rootScope.$on('keyup', function (e, keyEvent) {
// CTRL + S or CMD + S will override the default and save the build is possible
if (keyEvent.keycode == 83 && keyEvent.ctrlKey) {

View File

@@ -1,3 +1,4 @@
angular.module('app').controller('ShipyardController', ['$rootScope', function ($rootScope) {
$rootScope.title = 'Coriolis - Shipyard';
$rootScope.bodyClass = 'docking-bay';
}]);

View File

@@ -1,77 +0,0 @@
angular.module('app').directive('meter', function () {
return {
restrict: 'A',
scope: {
labels: '=',
keys: '=',
obj: '=',
max: '='
},
link: function (scope, element) {
var max = scope.max,
w = 90,
pLeft = 1,
pBottom = 2,
labelWidth = 45,
bHeight = 16,
bWidth = ((w - labelWidth) / max) - pLeft,
h = bHeight * scope.keys.length;
var data = [];
for(var i = 0; i < scope.keys.length; i++) {
data.push({name:scope.labels[i], val: scope.obj[scope.keys[i]]});
}
var svg = d3.select(element[0])
.append('svg')
.attr('width', w)
.attr('height', h)
.attr('viewBox', '0 0 ' + w + ' ' + h)
.attr('class', 'meter')
.attr('preserveAspectRatio', 'xMinYMin');
svg.selectAll("g").data(data)
.enter()
.append("g")
.attr('transform', function(d, i) {
return 'translate(' + labelWidth + ' ' + (i * bHeight) + ')';
})
.each(function(d, k) {
var g = d3.select(this);
for (var i = 0; i < max; i++) {
g.append('rect')
.attr("x", i * (bWidth + pLeft))
.attr("y", 0)
.attr("width", bWidth)
.attr("height", bHeight - pBottom);
}
});
svg.selectAll("text").data(data)
.enter()
.append('text')
.text(function(d) {
return d.name;
})
.attr("text-anchor", "end")
.attr("x", labelWidth - 3)
.attr("y", function(d, i) {
return (i * bHeight) + (bHeight) / 2;
});
function update() {
for(var i = 0; i < data.length; i++) {
data[i].val = scope.obj[scope.keys[i]];
}
svg.selectAll("g").data(data)
.selectAll('rect').attr('class', function(d, i) {
return (i + 1 <= d.val) ? 'active' : '';
});
}
scope.$watch('obj',update);
}
};
});