From 81d9d5b76da9943218955976a06231031e6df4d4 Mon Sep 17 00:00:00 2001 From: Xelio Date: Mon, 25 Mar 2013 03:05:28 +0800 Subject: [PATCH 1/6] Plugin AP List: Add pagination controls --- plugins/ap-list.css | 55 +++++++++++++++++++++++++++++++++++++++++ plugins/ap-list.user.js | 26 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/plugins/ap-list.css b/plugins/ap-list.css index 2e73f3b4..4f4830f4 100644 --- a/plugins/ap-list.css +++ b/plugins/ap-list.css @@ -90,4 +90,59 @@ .ap-list-link-selected { font-style:italic; +} + +.ap-list-center-div { + width: 50%; + margin: 0px auto; + +} + +.ap-list-page-control { + float:left; + padding: 0 5px; +} + +.ap-list-page-text { + float:left; + text-align: center; + color: rgb(32, 168, 177); +} + +#ap-list-current-p { + width: 20px; +} + +#ap-list-total-p { + width: 20px; +} + +.ap-list-triangle { + float:left; + clear:none; + border-style:solid; +} + +.ap-list-triangle-left { + border-color: transparent rgb(32, 168, 177) transparent transparent; +} + +.ap-list-triangle-left-half { + border-width: 7.5px 7.5px 7.5px 0px; +} + +.ap-list-triangle-left-full { + border-width: 7.5px 13px 7.5px 0px; +} + +.ap-list-triangle-right { + border-color: transparent transparent transparent rgb(32, 168, 177); +} + +.ap-list-triangle-right-half { + border-width: 7.5px 0px 7.5px 7.5px; +} + +.ap-list-triangle-right-full { + border-width: 7.5px 0px 7.5px 13px; } \ No newline at end of file diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 882a4ef9..5ddd7343 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -718,12 +718,37 @@ window.plugin.apList.setupList = function() { + 'plugin.apList.hideReloadLabel();return false;">↻ R' + '' + '
' + + '
' + ''; $('#sidebar').append(content); $('#ap-list-reload').hide(); } +window.plugin.apList.setupPagination = function() { + var content = '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
1
' + + '
/
' + + '
1
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
'// fix collapsion of parent caused by inner div's float:left + + '
'; + $('#ap-list-pagination').html(content); +} + window.plugin.apList.setupMapEvent = function() { map.on('zoomstart', function() { plugin.apList.setupMapEvent.zoomLevelBefore = map.getZoom(); @@ -758,6 +783,7 @@ var setup = function() { window.plugin.apList.setupTableColumns(); window.plugin.apList.setupCSS(); window.plugin.apList.setupList(); + window.plugin.apList.setupPagination(); window.plugin.apList.setupMapEvent(); window.addHook('requestFinished', window.plugin.apList.handleUpdate); } From 440a199b5b2cb57035d8a5e6b6c10820e03a9bda Mon Sep 17 00:00:00 2001 From: Xelio Date: Mon, 25 Mar 2013 23:53:41 +0800 Subject: [PATCH 2/6] Plugin AP List: Add pagination function --- plugins/ap-list.user.js | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 5ddd7343..62a69790 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -31,7 +31,9 @@ window.plugin.apList.sides = new Array(2); window.plugin.apList.sortedPortals = new Array(2); window.plugin.apList.playerApGainFunc = new Array(2); -window.plugin.apList.topMaxCount = 10; +window.plugin.apList.currentPage = [1,1]; +window.plugin.apList.totalPage = [1,1]; +window.plugin.apList.portalPerPage = 10; window.plugin.apList.sideLabelClass = {}; window.plugin.apList.tableColumns = new Array(2); @@ -60,13 +62,16 @@ window.plugin.apList.updatePortalTable = function(side) { + plugin.apList.tableHeaderBuilder(side) + ''; - table += '' - for(var i = 0; i < plugin.apList.topMaxCount; i++) { + table += ''; + var startingPortal = (plugin.apList.currentPage[side] - 1) * plugin.apList.portalPerPage; + for(var i = startingPortal; i < startingPortal + plugin.apList.portalPerPage; i++) { var portal = plugin.apList.sortedPortals[side][i]; table += plugin.apList.tableRowBuilder(side, portal); } table += ''; $('div#ap-list-table').html(table); + + plugin.apList.updatePaginationControl(); } window.plugin.apList.tableHeaderBuilder = function(side) { @@ -192,6 +197,11 @@ window.plugin.apList.getPortalLink = function(portal) { return div; } +window.plugin.apList.updatePaginationControl = function() { + $('#ap-list-current-p').html(plugin.apList.currentPage[plugin.apList.displaySide]); + $('#ap-list-total-p').html(plugin.apList.totalPage[plugin.apList.displaySide]); +} + // MAIN LOGIC FUNCTIONS ////////////////////////////////////////////////////////// // Loop through portals and get playerApGain, then put in sortedPortals by side and sort them by AP. @@ -240,14 +250,16 @@ window.plugin.apList.updateSortedPortals = function() { }); // Modify sortedPortals if any portal selected for destroy - if(plugin.apList.destroyPortalsGuid.length > 0) { - plugin.apList.handleDestroyPortal() - } + plugin.apList.handleDestroyPortal(); + // Update pagination control data + plugin.apList.updateTotalPages(); } // This function will make AP gain of field and link only count once if // one of the connected portal is selected for destroy window.plugin.apList.handleDestroyPortal = function() { + if(plugin.apList.destroyPortalsGuid.length === 0) return; + var enemy = window.plugin.apList.SIDE_ENEMY; var destroyedLinks = {}; var destroyedFields = {}; @@ -315,6 +327,12 @@ window.plugin.apList.handleDestroyPortal = function() { }); } +window.plugin.apList.updateTotalPages = function() { + $.each(plugin.apList.sortedPortals, function(side, portals) { + plugin.apList.totalPage[side] = Math.max(Math.ceil(portals.length / plugin.apList.portalPerPage), 1); + }); +} + window.plugin.apList.isSamePortal = function(a,b) { if(!a || !b) return false; if(a.team !== b.team) return false; @@ -578,6 +596,25 @@ window.plugin.apList.animPortalLocationIndicator = function() { } } +window.plugin.apList.changePage = function(step, toEnd) { + var side = plugin.apList.displaySide; + var originPage = plugin.apList.currentPage[side]; + + if(toEnd) { + if(step < 0) plugin.apList.currentPage[side] = 1; + if(step > 0) plugin.apList.currentPage[side] = plugin.apList.totalPage[side] + } else { + plugin.apList.currentPage[side] += step; + if(plugin.apList.currentPage[side] < 1) + plugin.apList.currentPage[side] = 1; + if(plugin.apList.currentPage[side] > plugin.apList.totalPage[side]) + plugin.apList.currentPage[side] = plugin.apList.totalPage[side]; + } + + if(plugin.apList.currentPage[side] !== originPage) + plugin.apList.updatePortalTable(side); +} + window.plugin.apList.destroyPortal = function(guid) { // Add to destroyPortalsGuid if not yet added, remove if already added var portalIndex = plugin.apList.destroyPortalIndex(guid); @@ -727,20 +764,20 @@ window.plugin.apList.setupList = function() { window.plugin.apList.setupPagination = function() { var content = '
' - + '
' + + '
' + '
' + '
' + '
' - + '
' + + '
' + '
' + '
' + '
1
' + '
/
' + '
1
' - + '
' + + '
' + '
' + '
' - + '
' + + '
' + '
' + '
' + '
' From 6897da0cb8dae217ca6cea6b51e7f7acee64ea53 Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Mar 2013 02:15:10 +0800 Subject: [PATCH 3/6] Plugin AP List: Add sorting function Clicking header of AP or EL will sort by correspond column. --- plugins/ap-list.user.js | 79 ++++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 62a69790..d1148c41 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -31,6 +31,13 @@ window.plugin.apList.sides = new Array(2); window.plugin.apList.sortedPortals = new Array(2); window.plugin.apList.playerApGainFunc = new Array(2); +window.plugin.apList.SORT_BY_AP = 'AP'; +window.plugin.apList.SORT_BY_EL = 'EL'; +window.plugin.apList.sortBy = window.plugin.apList.SORT_BY_AP; +window.plugin.apList.SORT_ASC = 1; +window.plugin.apList.SORT_DESC = -1; +window.plugin.apList.sortOptions = {}; + window.plugin.apList.currentPage = [1,1]; window.plugin.apList.totalPage = [1,1]; window.plugin.apList.portalPerPage = 10; @@ -80,8 +87,10 @@ window.plugin.apList.tableHeaderBuilder = function(side) { $.each(plugin.apList.tableColumns[side], function(ind, column) { var cssClass = column.headerTooltip ? (column.cssClass + ' help') : column.cssClass; var title = column.headerTooltip ? column.headerTooltip : ''; + var onclick = column.headerOnClick ? column.headerOnClick: ''; headerRow += '' + column.header + ''; @@ -244,9 +253,7 @@ window.plugin.apList.updateSortedPortals = function() { plugin.apList.sortedPortals[side].push(portal); }); $.each(plugin.apList.sides, function(ind, side) { - plugin.apList.sortedPortals[side].sort(function(a, b) { - return b.playerApGain.totalAp - a.playerApGain.totalAp; - }); + plugin.apList.sortedPortals[side].sort(plugin.apList.comparePortal); }); // Modify sortedPortals if any portal selected for destroy @@ -322,9 +329,7 @@ window.plugin.apList.handleDestroyPortal = function() { }); // Sorting portals with updated AP - plugin.apList.sortedPortals[enemy].sort(function(a, b) { - return b.playerApGain.totalAp - a.playerApGain.totalAp; - }); + plugin.apList.sortedPortals[enemy].sort(plugin.apList.comparePortal); } window.plugin.apList.updateTotalPages = function() { @@ -407,9 +412,6 @@ window.plugin.apList.getDeployOrUpgradeApGain = function(d) { upgradedReso.push(targetReso); // Counting upgrade or deploy (targetReso.level === 0) ? deployCount++ : upgradedCount++; - totalAp += (targetReso.level === 0) - ? DEPLOY_RESONATOR - : UPGRADE_ANOTHERS_RESONATOR; availableCount--; } @@ -537,6 +539,29 @@ window.plugin.apList.getShieldsMitigation = function(portal) { return shieldsMitigation; } +// For using in .sort(func) of sortedPortals +window.plugin.apList.comparePortal = function(a,b) { + var result = 0; + var options = plugin.apList.sortOptions[plugin.apList.sortBy]; + + $.each(options, function(indO, option) { + var aProperty = a; + var bProperty = b; + // Walking down the chain + $.each(option.chain, function(indPN, propertyName) { + aProperty = aProperty[propertyName]; + bProperty = bProperty[propertyName]; + }); + // compare next porperty if equal + if(aProperty === bProperty) return true; + + result = (aProperty > bProperty ? 1 : -1) * option.order; + return false; + }); + + return result; +} + // FEATURE TOGGLES AND INTERACTION HANDLER /////////////////////////////////////// window.plugin.apList.enableCache = function() { @@ -598,7 +623,7 @@ window.plugin.apList.animPortalLocationIndicator = function() { window.plugin.apList.changePage = function(step, toEnd) { var side = plugin.apList.displaySide; - var originPage = plugin.apList.currentPage[side]; + var oldPage = plugin.apList.currentPage[side]; if(toEnd) { if(step < 0) plugin.apList.currentPage[side] = 1; @@ -611,10 +636,19 @@ window.plugin.apList.changePage = function(step, toEnd) { plugin.apList.currentPage[side] = plugin.apList.totalPage[side]; } - if(plugin.apList.currentPage[side] !== originPage) + if(plugin.apList.currentPage[side] !== oldPage) plugin.apList.updatePortalTable(side); } +window.plugin.apList.changeSorting = function(sortBy) { + var oldSortBy = plugin.apList.sortBy; + plugin.apList.sortBy = sortBy; + if(plugin.apList.sortBy !== oldSortBy) { + plugin.apList.updateSortedPortals(); + plugin.apList.updatePortalTable(plugin.apList.displaySide); + } +} + window.plugin.apList.destroyPortal = function(guid) { // Add to destroyPortalsGuid if not yet added, remove if already added var portalIndex = plugin.apList.destroyPortalIndex(guid); @@ -687,6 +721,23 @@ window.plugin.apList.setupVar = function() { = "#ap-list-eny"; } +window.plugin.apList.setupSorting = function() { + var optionELAsc = { + order: plugin.apList.SORT_ASC, + chain: ['effectiveLevel','effectiveLevel']}; + var optionAPDesc = { + order: plugin.apList.SORT_DESC, + chain: ['playerApGain','totalAp']}; + var optionGuidDesc = { + order: plugin.apList.SORT_DESC, + chain: ['guid']}; + + // order by EL -> AP -> guid + plugin.apList.sortOptions[plugin.apList.SORT_BY_EL] = [optionELAsc, optionAPDesc, optionGuidDesc]; + // order by AP -> EL -> guid + plugin.apList.sortOptions[plugin.apList.SORT_BY_AP] = [optionAPDesc, optionELAsc, optionGuidDesc]; +} + // Setup table columns for header builder and row builder window.plugin.apList.setupTableColumns = function() { var enemyColumns = new Array(); @@ -695,12 +746,15 @@ window.plugin.apList.setupTableColumns = function() { // AP and Eff. LV columns are same in enemy and friendly table var apColumn = { header: 'AP', + headerOnClick: 'plugin.apList.changeSorting(plugin.apList.SORT_BY_AP);', + headerTooltip: 'Click to sort by AP', cssClass: 'ap-list-td-ap', contentFunction: plugin.apList.getPortalApText }; var effectiveLevelColumn = { header: 'EL', - headerTooltip: 'Effective Level', + headerOnClick: 'plugin.apList.changeSorting(plugin.apList.SORT_BY_EL);', + headerTooltip: 'Effective Level\nClick to sort by EL', cssClass: 'ap-list-td-eff-lv', contentFunction: plugin.apList.getPortalEffectiveLvText }; @@ -817,6 +871,7 @@ window.plugin.apList.setupMapEvent = function() { var setup = function() { window.plugin.apList.setupVar(); + window.plugin.apList.setupSorting(); window.plugin.apList.setupTableColumns(); window.plugin.apList.setupCSS(); window.plugin.apList.setupList(); From 8f9049fdf3d81e3897ecd40db447cc2d9d59b82e Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Mar 2013 02:20:46 +0800 Subject: [PATCH 4/6] Plugin AP List: Update current page number if total page name updated to lower than current page number. --- plugins/ap-list.user.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index d1148c41..453eee5d 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -335,6 +335,7 @@ window.plugin.apList.handleDestroyPortal = function() { window.plugin.apList.updateTotalPages = function() { $.each(plugin.apList.sortedPortals, function(side, portals) { plugin.apList.totalPage[side] = Math.max(Math.ceil(portals.length / plugin.apList.portalPerPage), 1); + plugin.apList.currentPage[side] = Math.min(plugin.apList.totalPage[side], plugin.apList.currentPage[side]); }); } From 26cd8b2a8d8d15ca668e3776fe93b66aa92dd240 Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Mar 2013 03:39:54 +0800 Subject: [PATCH 5/6] Plugin AP List: Fix some minor bugs and add comments --- plugins/ap-list.user.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 453eee5d..47c50f9c 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -374,22 +374,16 @@ window.plugin.apList.getDeployOrUpgradeApGain = function(d) { // by others(only level lower than player level) or by player. for(var i = 0; i < 8; i++) { var reso = d.resonatorArray.resonators[i]; - + // Empty reso if(!reso) { - // Empty reso - reso = {slot: i, level: 0}; - otherReso.push(reso); + otherReso.push({slot: i, level: 0}); continue; } - // By player if(reso.ownerGuid === window.PLAYER.guid) { - if(!playerResoCount[reso.level]) - playerResoCount[reso.level] = 0; - playerResoCount[reso.level]++; + playerResoCount[reso.level] = (playerResoCount[reso.level] || 0) + 1; continue; } - // By others and level lower than player if(reso.level < window.PLAYER.level) { otherReso.push(reso); @@ -541,6 +535,13 @@ window.plugin.apList.getShieldsMitigation = function(portal) { } // For using in .sort(func) of sortedPortals +// Use options in plugin.apList.sortOptions. Each type of sortBy has +// array of options. Option consist of an ordering and a property chain. +// +// Sorting done by loop through the options, get the property by +// property chain of each option, compare the property of two object +// with the ordering of option and return the result when the first +// differece is found. window.plugin.apList.comparePortal = function(a,b) { var result = 0; var options = plugin.apList.sortOptions[plugin.apList.sortBy]; @@ -579,7 +580,15 @@ window.plugin.apList.disableCache = function() { } window.plugin.apList.selectPortal = function(guid) { - renderPortalDetails(guid); + // Add error catching to avoid following link of portal if error + // occured in renderPortalDetails or hooked plugin + try { + renderPortalDetails(guid); + } catch(e) { + console.error(e.message); + console.log(e.stack); + console.log('Skipping error in renderPortalDetails or hooked plugin') + } plugin.apList.setPortalLocationIndicator(guid); } @@ -720,6 +729,8 @@ window.plugin.apList.setupVar = function() { = "#ap-list-frd"; plugin.apList.sideLabelClass[plugin.apList.SIDE_ENEMY] = "#ap-list-eny"; + plugin.apList.sortedPortals[plugin.apList.SIDE_FRIENDLY] = new Array(); + plugin.apList.sortedPortals[plugin.apList.SIDE_ENEMY] = new Array(); } window.plugin.apList.setupSorting = function() { From f6d5cc621eec44cfc139d38eba6334b57df0582a Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 26 Mar 2013 03:41:32 +0800 Subject: [PATCH 6/6] Plugin AP List: Bump version number --- plugins/ap-list.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 47c50f9c..1a6b715d 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @id iitc-plugin-ap-list@xelio // @name IITC plugin: AP List -// @version 0.4.5.@@DATETIMEVERSION@@ +// @version 0.5.0.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@