'use strict'; /** * Services for each tour step when you unlock features */ angular.module('habitrpg').factory('Guide', ['$rootScope', 'User', '$timeout', function($rootScope, User, $timeout) { /** * Init and show the welcome tour. Note we do it listening to a $rootScope broadcasted 'userLoaded' message, * this because we need to determine whether to show the tour *after* the user has been pulled from the server, * otherwise it's always start off as true, and then get set to false later */ $rootScope.$on('userUpdated', initTour); function initTour(){ if (User.user.flags.showTour === false) return; var tourSteps = [ { element: ".main-herobox", title: window.env.t('welcomeHabit'), content: window.env.t('welcomeHabitT1') + " Justin, " + window.env.t('welcomeHabitT2'), }, { element: ".main-herobox", title: window.env.t('yourAvatar'), content: window.env.t('yourAvatarText'), }, { element: ".main-herobox", title: window.env.t('avatarCustom'), content: window.env.t('avatarCustomText'), }, { element: "#bars", title: window.env.t('hitPoints'), content: window.env.t('hitPointsText'), }, { element: "#bars", title: window.env.t('expPoints'), content: window.env.t('expPointsText'), }, { element: "ul.habits", title: window.env.t('typeGoals'), content: window.env.t('typeGoalsText'), placement: "top" }, { element: "ul.habits", title: window.env.t('habits'), content: window.env.t('tourHabits'), placement: "top" }, { element: "ul.dailys", title: window.env.t('dailies'), content: window.env.t('tourDailies'), placement: "top" }, { element: "ul.todos", title: window.env.t('todos'), content: window.env.t('tourTodos'), placement: "top" }, { element: "ul.main-list.rewards", title: window.env.t('rewards'), content: window.env.t('tourRewards'), placement: "top" }, { element: "ul.habits li:first-child", title: window.env.t('hoverOver'), content: window.env.t('hoverOverText'), placement: "right" }, { element: "ul.habits li:first-child", title: window.env.t('unlockFeatures'), content: window.env.t('unlockFeaturesT1') + " " + window.env.t('habitWiki') + " " + window.env.t('unlockFeaturesT2'), placement: "right" } ]; _.each(tourSteps, function(step){ if (env.worldDmg.guide) { step.content = "
" + step.content + "
"; } else { step.content = "
" + step.content + "
"; } }); $('.main-herobox').popover('destroy'); var tour = new Tour({ template: "
" + "

" + "
" + "" + "" + "
" + "
", onEnd: function(){ User.set({'flags.showTour': false}); } }); tourSteps.forEach(function(step) { tour.addStep(_.defaults(step, {html: true})); }); tour.restart(); // Tour doesn't quite mesh with our handling of flags.showTour, just restart it on page load //tour.start(true); }; var alreadyShown = function(before, after) { return !(!before && after === true); }; var showPopover = function(selector, title, html, placement) { if (!placement) placement = 'bottom'; $(selector).popover('destroy'); var button = ""; if (env.worldDmg.guide) { html = "
" + html + '
' + button + '
'; } else { html = "
" + html + '
' + button + '
'; } $(selector).popover({ title: title, placement: placement, trigger: 'manual', html: true, content: html }).popover('show'); }; $rootScope.$watch('user.flags.customizationsNotification', function(after, before) { if (alreadyShown(before, after)) return; showPopover('.main-herobox', window.env.t('customAvatar'), window.env.t('customAvatarText'), 'bottom'); }); $rootScope.$watch('user.flags.itemsEnabled', function(after, before) { if (alreadyShown(before, after)) return; var html = window.env.t('storeUnlockedText'); showPopover('div.rewards', window.env.t('storeUnlocked'), html, 'left'); }); $rootScope.$watch('user.flags.partyEnabled', function(after, before) { if (alreadyShown(before, after)) return; var html = window.env.t('partySysText'); showPopover('.user-menu', window.env.t('partySys'), html, 'bottom'); }); $rootScope.$watch('user.flags.dropsEnabled', function(after, before) { if (alreadyShown(before, after)) return; var eggs = User.user.items.eggs || {}; if (!eggs) { eggs['Wolf'] = 1; // This is also set on the server } $rootScope.openModal('dropsEnabled'); }); $rootScope.$watch('user.flags.rebirthEnabled', function(after, before) { if (alreadyShown(before, after)) return; $rootScope.openModal('rebirthEnabled'); }); /** * Classes Tour */ function classesTour(){ // TODO notice my hack-job `onShow: _.once()` functions. Without these, the syncronous path redirects won't properly handle showing tour var tourSteps = [ { path: '/#/options/inventory/equipment', onShow: _.once(function(tour){ $timeout(function(){tour.goTo(0)}); }), element: '.equipment-tab', title: window.env.t('classGear'), content: window.env.t('classGearText', {klass: User.user.stats.class}) }, { path: '/#/options/profile/stats', onShow: _.once(function(tour){ $timeout(function(){tour.goTo(1)}); }), element: ".allocate-stats", title: window.env.t('stats'), content: window.env.t('classStats'), }, { element: ".auto-allocate", title: window.env.t('autoAllocate'), placement: 'left', content: window.env.t('autoAllocateText'), }, { element: ".meter.mana", title: window.env.t('spells'), content: window.env.t('spellsText') + " " + window.env.t('toDo') + "." }, { orphan: true, title: window.env.t('readMore'), content: window.env.t('moreClass') + " Wikia." } ]; _.each(tourSteps, function(step){ if (env.worldDmg.guide) { step.content = "
" + step.content + "
"; } else { step.content = "
" + step.content + "
"; } }); $('.allocate-stats').popover('destroy'); var tour = new Tour({ // onEnd: function(){ // User.set({'flags.showTour': false}); // } }); tourSteps.forEach(function(step) { tour.addStep(_.defaults(step, {html: true})); }); tour.restart(); // Tour doesn't quite mesh with our handling of flags.showTour, just restart it on page load //tour.start(true); }; return { initTour: initTour, classesTour: classesTour }; }]);