refactor(bs3): port quests modals, fix restore modal and various bugs

This commit is contained in:
Matteo Pagliazzi 2014-02-02 16:43:58 +01:00
parent 571954b5cf
commit 07593dc122
11 changed files with 54 additions and 40 deletions

View file

@ -27,7 +27,6 @@ angular.module('authCtrl', [])
runAuth = function(id, token) {
User.authenticate(id, token, function(err) {
$window.location.href = '/';
//$rootScope.modals.login = false;
});
};

View file

@ -222,7 +222,7 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
}
$scope.newGroup = newGroup()
$scope.create = function(group){
if (User.user.balance < 1) return $rootScope.modals.buyGems = true;
if (User.user.balance < 1) return $rootScope.openModal('buyGems');
if (confirm("Create Guild for 4 Gems?")) {
group.$save(function(saved){

View file

@ -1,5 +1,5 @@
habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', 'Content',
function($rootScope, $scope, $window, User, Content) {
habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User', 'Content', '$modal',
function($rootScope, $scope, $window, User, Content, $modal) {
var user = User.user;
@ -87,7 +87,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User',
$scope.purchase = function(type, item){
var gems = User.user.balance * 4;
if(gems < item.value) return $rootScope.modals.buyGems = true;
if(gems < item.value) return $rootScope.openModal('buyGems');
var string = (type == 'hatchingPotion') ? 'hatching potion' : type; // give hatchingPotion a space
var message = "Buy this " + string + " with " + item.value + " of your " + gems + " Gems?"
if($window.confirm(message))
@ -127,12 +127,13 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User',
if (item.lvl && item.lvl > user.stats.lvl)
return alert("You must be level " + item.lvl + '.');
$rootScope.selectedQuest = item;
$rootScope.modals.showQuest = true;
$modal.open({
templateUrl: 'modals/showQuest.html',
controller: 'InventoryCtrl'
});
}
$scope.closeQuest = function(){
$rootScope.selectedQuest = undefined;
$rootScope.modals.showQuest = false;
$rootScope.modals.buyQuest = false;
}
$scope.questInit = function(){
$rootScope.party.$questAccept({key:$scope.selectedQuest.key}, function(){
@ -148,7 +149,10 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', '$window', 'User',
if (!completedPrevious)
return $scope.purchase("quests", item);
$rootScope.selectedQuest = item;
$rootScope.modals.buyQuest = true;
$modal.open({
templateUrl: 'modals/buyQuest.html',
controller: 'InventoryCtrl'
});
}
}
]);

View file

@ -133,13 +133,30 @@ habitrpg.controller('NotificationCtrl',
}
});
// Math updates modal
$rootScope.$watch('!user.flags.mathUpdates', function(after, before){
if (after === before || after !== true) return;
if (after == before || after != true) return;
$modal.open({
templateUrl: 'modals/mathUpdates.html'
});
});
// Completed quest modal
$rootScope.$watch('user.party.quest.completed', function(after, before){
if (after == before || after != true) return;
$modal.open({
templateUrl: 'modals/questCompleted.html',
controller: 'InventoryCtrl'
});
});
$rootScope.$watch('party.quest.key && !party.quest.active && !questHold && party.quest.members[user._id] == undefined', function(after, before){
if (after == before || after != true) return;
$modal.open({
templateUrl: 'modals/questInvitation.html'
});
});
$rootScope.$on('responseError', function(ev, error){
Notification.error(error);
});

View file

@ -67,7 +67,7 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
// Open a modal from a template expression (like ng-click,...)
// Otherwise use the proper $modal.open
$rootScope.openModal = function(template, controller, scope){
$modal.open({
return $modal.open({
templateUrl: 'modals/' + template + '.html',
controller: controller, // optional
scope: scope // optional

View file

@ -78,12 +78,11 @@ habitrpg.controller('SettingsCtrl',
}
$scope.restoreValues = {};
$rootScope.$watch('modals.restore', function(value){
if(value === true){
$scope.restoreValues.stats = angular.copy(User.user.stats);
$scope.restoreValues.achievements = {streak: User.user.achievements.streak || 0};
}
})
$rootScope.openRestoreModal = function(){
$scope.restoreValues.stats = angular.copy(User.user.stats);
$scope.restoreValues.achievements = {streak: User.user.achievements.streak || 0};
$rootScope.openModal('restore', undefined, $scope);
};
$scope.restore = function(){
var stats = $scope.restoreValues.stats,

View file

@ -53,10 +53,10 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$
if (fullSet) {
if (confirm("Purchase for 5 Gems?") !== true) return;
if (User.user.balance < cost) return $rootScope.modals.buyGems = true;
if (User.user.balance < cost) return $rootScope.openModal('buyGems');
} else if (!User.user.fns.dotGet('purchased.' + path)) {
if (confirm("Purchase for 2 Gems?") !== true) return;
if (User.user.balance < cost) return $rootScope.modals.buyGems = true;
if (User.user.balance < cost) return $rootScope.openModal('buyGems');
}
User.user.ops.unlock({query:{path:path}})
}

View file

@ -65,7 +65,7 @@ script(type='text/ng-template', id='partials/options.settings.settings.html')
br
button.btn(ng-click='showBailey()', popover-trigger='mouseenter', popover-placement='right', popover=env.t('showBaileyPop'))= env.t('showBailey')
br
button.btn(ng-click='openModal("restore", "SettingsCtrl")', popover-trigger='mouseenter', popover-placement='right', popover=env.t('fixValPop'))= env.t('fixVal')
button.btn(ng-click='openRestoreModal()', popover-trigger='mouseenter', popover-placement='right', popover=env.t('fixValPop'))= env.t('fixVal')
div(ng-if='user.preferences.disableClasses==true')
button.btn(ng-click='user.ops.changeClass({})', popover-trigger='mouseenter', popover-placement='right', popover=env.t('enableClassPop'))= env.t('enableClass')
div(ng-if='!user.preferences.disableClasses && user.flags.classSelected')

View file

@ -1,5 +1,4 @@
.user-menu(ng-controller='AuthCtrl')
button.task-action-btn.tile.solid(ng-hide='authenticated()', style='cursor: pointer;', ng-click="modals.login = true")=env.t('loginAndReg')
ul.nav.site-nav(ng-show='authenticated()')
li.flyout
h1.task-action-btn.tile.solid.user-reporter {{user.profile.name}}

View file

@ -11,7 +11,6 @@ script(id='partials/options.social.party.quest-rewards.html', type='text/ng-temp
td {{quest.drop.gp}}
=env.t('gold')
//div(modal='user.party.quest.completed', ng-controller='InventoryCtrl')
script(type='text/ng-template', id='modals/questCompleted.html')
.modal-header
h3 "{{Content.quests[user.party.quest.completed].text}}"
@ -20,9 +19,8 @@ script(type='text/ng-template', id='modals/questCompleted.html')
p {{Content.quests[user.party.quest.completed].completion}}
quest-rewards(key='{{user.party.quest.completed}}', header=env.t('youReceived'))
.modal-footer
button.btn.btn-default.btn-primary(ng-click='set({"party.quest.completed":""})')=env.t('accept')
button.btn.btn-default.btn-primary(ng-click='set({"party.quest.completed":""}); $close()')=env.t('accept')
//div(modal='modals.showQuest', ng-controller='InventoryCtrl')
script(type='text/ng-template', id='modals/showQuest.html')
.modal-header
h3 {{selectedQuest.text}}
@ -35,10 +33,9 @@ script(type='text/ng-template', id='modals/showQuest.html')
.npc_ian.pull-left
p=env.t('questSend')
.modal-footer
button.btn.btn-default.btn-small.btn-cancel(ng-click='closeQuest()')=env.t('cancel')
button.btn.btn-default.btn-primary(ng-click='questInit()')=env.t('inviteParty')
button.btn.btn-default.btn-small.btn-cancel(ng-click='closeQuest(); $close()')=env.t('cancel')
button.btn.btn-default.btn-primary(ng-click='questInit(); $close()')=env.t('inviteParty')
//div(modal='modals.buyQuest', ng-controller='InventoryCtrl')
script(type='text/ng-template', id='modals/buyQuest.html')
.modal-header
h3 {{selectedQuest.text}}
@ -47,10 +44,9 @@ script(type='text/ng-template', id='modals/buyQuest.html')
div(ng-bind-html='selectedQuest.notes')
quest-rewards(key='{{selectedQuest.key}}')
.modal-footer
button.btn.btn-large.cancel(ng-click='closeQuest()')=env.t('neverMind')
button.btn.btn-default.btn-large.btn-primary(ng-click='purchase("quests", quest);closeQuest()')=env.t('buyQuest')
button.btn.btn-large.cancel(ng-click='closeQuest(); $close()')=env.t('neverMind')
button.btn.btn-default.btn-large.btn-primary(ng-click='purchase("quests", quest); closeQuest(); $close()')=env.t('buyQuest')
//div(modal='party.quest.key && !party.quest.active && !questHold && party.quest.members[user._id] == undefined')
script(type='text/ng-template', id='modals/questInvitation.html')
.modal-header
h3=env.t('questInvitation')
@ -59,6 +55,6 @@ script(type='text/ng-template', id='modals/questInvitation.html')
div(ng-bind-html='Content.quests[party.quest.key].notes')
quest-rewards(key='{{party.quest.key}}')
.modal-footer
button.btn.btn-default.btn-small.btn-cancel(ng-click='questHold = true')=env.t('askLater')
button.btn.btn-default.btn-small.btn-cancel(ng-click='party.$questReject()')=env.t('reject')
button.btn.btn-default.btn-primary(ng-click='party.$questAccept()')=env.t('accept')
button.btn.btn-default.btn-small.btn-cancel(ng-click='questHold = true; $close()')=env.t('askLater')
button.btn.btn-default.btn-small.btn-cancel(ng-click='party.$questReject(); $close()')=env.t('reject')
button.btn.btn-default.btn-primary(ng-click='party.$questAccept(); $close()')=env.t('accept')

View file

@ -18,33 +18,33 @@ script(type='text/ng-template', id='modals/restore.html')
form#restore-form.form-horizontal
h3=env.t('stats')
.option-group.option-medium
input.option-content(type='number', step="any", data-for='stats.hp', ng-model='restoreValues.stats.hp')
input.option-content(type='number', step="any", data-for='stats.hp', ng-model='$parent.restoreValues.stats.hp')
span.input-suffix=env.t('health')
.option-group.option-medium
input.option-content(type='number', step="any", data-for='stats.exp', ng-model='restoreValues.stats.exp')
input.option-content(type='number', step="any", data-for='stats.exp', ng-model='$parent.restoreValues.stats.exp')
span.input-suffix=env.t('experience')
.option-group.option-medium
input.option-content(type='number', step="any", data-for='stats.gp', ng-model='restoreValues.stats.gp')
input.option-content(type='number', step="any", data-for='stats.gp', ng-model='$parent.restoreValues.stats.gp')
//input.option-content(type='number', step="any", data-for='stats.gp', ng-model='restoreValues.stats.gp',disabled)
span.input-suffix=env.t('gold')
//-p.alert
small=env.t('disabledWinterEvent')
.option-group.option-medium
input.option-content(type='number', step="any", data-for='stats.mp', ng-model='restoreValues.stats.mp')
input.option-content(type='number', step="any", data-for='stats.mp', ng-model='$parent.restoreValues.stats.mp')
span.input-suffix=env.t('mana')
.option-group.option-medium
input.option-content(type='number', data-for='stats.lvl', ng-model='restoreValues.stats.lvl')
input.option-content(type='number', data-for='stats.lvl', ng-model='$parent.restoreValues.stats.lvl')
span.input-suffix=env.t('level')
h3=env.t('achievements')
.option-group.option-medium
input.option-content(type='number', data-for='achievements.streak', ng-model='restoreValues.achievements.streak')
input.option-content(type='number', data-for='achievements.streak', ng-model='$parent.restoreValues.achievements.streak')
span.input-suffix=env.t('fix21Streaks')
//- This is causing too many problems for users
h3=env.t('other')
a.btn.btn-small.btn-warning(ng-controller='FooterCtrl', ng-click='addMissedDay()')=env.t('triggerDay')
.modal-footer
button.btn.btn-default.cancel(ng-click='$close()')=env.t('discardChanges')
button.btn.btn-primary(ng-click='$close(); restore()')=env.t('saveAndClose')
button.btn.btn-primary(ng-click='restore(); $close();')=env.t('saveAndClose')
script(type='text/ng-template', id='modals/delete.html')
.modal-header