bit hacky, but get IITC's COMM to match the stock intel COMM in it's tabs

see https://plus.google.com/105383756361375410867/posts/b9ihAer4Fxm
This commit is contained in:
Jon Atkins 2015-01-22 20:24:34 +00:00
parent 712b954910
commit 0dcada2c3b
3 changed files with 132 additions and 86 deletions

View File

@ -1,5 +1,21 @@
window.chat = function() {}; window.chat = function() {};
//WORK IN PROGRESS - NOT YET USED!!
window.chat.commTabs = [
// channel: the COMM channel ('tab' parameter in server requests)
// name: visible name
// inputPrompt: string for the input prompt
// inputColor: (optional) color for input
// sendMessage: (optional) function to send the message (to override the default of sendPlext)
// globalBounds: (optional) if true, always use global latLng bounds
{channel:'all', name:'All', inputPrompt: 'broadcast:', inputColor:'#f66'},
{channel:'faction', name:'Aaction', inputPrompt: 'tell faction:'},
{channel:'alerts', name:'Alerts', inputPrompt: 'tell Jarvis:', inputColor: '#666', globalBounds: true, sendMessage: function() {
alert("Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?\n(You can't chat to the 'alerts' channel!)");
}},
];
window.chat.handleTabCompletion = function() { window.chat.handleTabCompletion = function() {
var el = $('#chatinput input'); var el = $('#chatinput input');
var curPos = el.get(0).selectionStart; var curPos = el.get(0).selectionStart;
@ -38,8 +54,8 @@ window.chat.handleTabCompletion = function() {
window.chat._oldBBox = null; window.chat._oldBBox = null;
window.chat.genPostData = function(isFaction, storageHash, getOlderMsgs) { window.chat.genPostData = function(channel, storageHash, getOlderMsgs) {
if(typeof isFaction !== 'boolean') throw('Need to know if public or faction chat.'); if (typeof channel !== 'string') throw ('API changed: isFaction flag now a channel string - all, faction, alerts');
var b = clampLatLngBounds(map.getBounds()); var b = clampLatLngBounds(map.getBounds());
@ -66,6 +82,10 @@ window.chat.genPostData = function(isFaction, storageHash, getOlderMsgs) {
chat._public.oldestTimestamp = -1; chat._public.oldestTimestamp = -1;
chat._public.newestTimestamp = -1; chat._public.newestTimestamp = -1;
chat._alerts.data = {};
chat._alerts.oldestTimestamp = -1;
chat._alerts.newestTimestamp = -1;
chat._oldBBox = b; chat._oldBBox = b;
} }
@ -79,7 +99,7 @@ window.chat.genPostData = function(isFaction, storageHash, getOlderMsgs) {
maxLngE6: Math.round(ne.lng*1E6), maxLngE6: Math.round(ne.lng*1E6),
minTimestampMs: -1, minTimestampMs: -1,
maxTimestampMs: -1, maxTimestampMs: -1,
tab: isFaction ? 'faction' : 'all' tab: channel,
} }
if(getOlderMsgs) { if(getOlderMsgs) {
@ -123,7 +143,7 @@ window.chat.requestFaction = function(getOlderMsgs, isRetry) {
if(isIdle()) return renderUpdateStatus(); if(isIdle()) return renderUpdateStatus();
chat._requestFactionRunning = true; chat._requestFactionRunning = true;
var d = chat.genPostData(true, chat._faction, getOlderMsgs); var d = chat.genPostData('faction', chat._faction, getOlderMsgs);
var r = window.postAjax( var r = window.postAjax(
'getPlexts', 'getPlexts',
d, d,
@ -153,8 +173,6 @@ window.chat.handleFaction = function(data, olderMsgs) {
runHooks('factionChatDataAvailable', {raw: data, processed: chat._faction.data}); runHooks('factionChatDataAvailable', {raw: data, processed: chat._faction.data});
window.chat.renderFaction(oldMsgsWereAdded); window.chat.renderFaction(oldMsgsWereAdded);
if(data.success.length >= CHAT_FACTION_ITEMS) chat.needMoreMessages();
} }
window.chat.renderFaction = function(oldMsgsWereAdded) { window.chat.renderFaction = function(oldMsgsWereAdded) {
@ -163,7 +181,7 @@ window.chat.renderFaction = function(oldMsgsWereAdded) {
// //
// public // all
// //
window.chat._requestPublicRunning = false; window.chat._requestPublicRunning = false;
@ -172,7 +190,7 @@ window.chat.requestPublic = function(getOlderMsgs, isRetry) {
if(isIdle()) return renderUpdateStatus(); if(isIdle()) return renderUpdateStatus();
chat._requestPublicRunning = true; chat._requestPublicRunning = true;
var d = chat.genPostData(false, chat._public, getOlderMsgs); var d = chat.genPostData('all', chat._public, getOlderMsgs);
var r = window.postAjax( var r = window.postAjax(
'getPlexts', 'getPlexts',
d, d,
@ -200,46 +218,63 @@ window.chat.handlePublic = function(data, olderMsgs) {
runHooks('publicChatDataAvailable', {raw: data, processed: chat._public.data}); runHooks('publicChatDataAvailable', {raw: data, processed: chat._public.data});
switch(chat.getActive()) { window.chat.renderPublic(oldMsgsWereAdded);
case 'public': window.chat.renderPublic(oldMsgsWereAdded); break;
case 'compact': window.chat.renderCompact(oldMsgsWereAdded); break;
case 'full': window.chat.renderFull(oldMsgsWereAdded); break;
}
if(data.success.length >= CHAT_PUBLIC_ITEMS) chat.needMoreMessages();
} }
window.chat.renderPublic = function(oldMsgsWereAdded) { window.chat.renderPublic = function(oldMsgsWereAdded) {
// only keep player data chat.renderData(chat._public.data, 'chatall', oldMsgsWereAdded);
var data = $.map(chat._public.data, function(entry) {
if(!entry[1]) return [entry];
});
chat.renderData(data, 'chatpublic', oldMsgsWereAdded);
} }
window.chat.renderCompact = function(oldMsgsWereAdded) {
var data = {}; //
$.each(chat._public.data, function(guid, entry) { // alerts
// skip player msgs //
if(!entry[1]) return true;
var nick = entry[3]; window.chat._requestAlertsRunning = false;
// ignore if player has newer data window.chat.requestAlerts = function(getOlderMsgs, isRetry) {
if(data[nick] && data[nick][0] > entry[0]) return true; if(chat._requestAlertsRunning && !isRetry) return;
data[nick] = entry; if(isIdle()) return renderUpdateStatus();
}); chat._requestAlertsRunning = true;
// data keys are now player nicks instead of message guids. However,
// it is all the same to renderData. var d = chat.genPostData('alerts', chat._alerts, getOlderMsgs);
chat.renderData(data, 'chatcompact', oldMsgsWereAdded); var r = window.postAjax(
'getPlexts',
d,
function(data, textStatus, jqXHR) { chat.handleAlerts(data, getOlderMsgs); },
isRetry
? function() { window.chat._requestAlertsRunning = false; }
: function() { window.chat.requestAlerts(getOlderMsgs, true) }
);
} }
window.chat.renderFull = function(oldMsgsWereAdded) {
// only keep automatically generated data window.chat._alerts = {data:{}, oldestTimestamp:-1, newestTimestamp:-1};
var data = $.map(chat._public.data, function(entry) { window.chat.handleAlerts = function(data, olderMsgs) {
if(entry[1]) return [entry]; chat._requestAlertsRunning = false;
});
chat.renderData(data, 'chatfull', oldMsgsWereAdded); if(!data || !data.success) {
window.failedRequestCount++;
return console.warn('alerts chat error. Waiting for next auto-refresh.');
}
if(data.success.length === 0) return;
var old = chat._alerts.oldestTimestamp;
chat.writeDataToHash(data, chat._alerts, undefined, olderMsgs); //NOTE: isPublic passed as undefined - it's nether public or private!
var oldMsgsWereAdded = old !== chat._alerts.oldestTimestamp;
// no hoot for alerts - API change planned here...
// runHooks('alertsChatDataAvailable', {raw: data, processed: chat._alerts.data});
window.chat.renderAlerts(oldMsgsWereAdded);
} }
window.chat.renderAlerts = function(oldMsgsWereAdded) {
chat.renderData(chat._alerts.data, 'chatalerts', oldMsgsWereAdded);
}
// //
// common // common
@ -271,7 +306,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is
if (storageHash.newestTimestamp === -1 || storageHash.newestTimestamp < time) storageHash.newestTimestamp = time; if (storageHash.newestTimestamp === -1 || storageHash.newestTimestamp < time) storageHash.newestTimestamp = time;
//remove "Your X on Y was destroyed by Z" from the faction channel //remove "Your X on Y was destroyed by Z" from the faction channel
if (systemNarrowcast && !isPublicChannel) return true; // if (systemNarrowcast && !isPublicChannel) return true;
var msg = '', nick = ''; var msg = '', nick = '';
$.each(json[2].plext.markup, function(ind, markup) { $.each(json[2].plext.markup, function(ind, markup) {
@ -326,21 +361,21 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is
}); });
//skip secure messages on the public channel // //skip secure messages on the public channel
if (isPublicChannel && isSecureMessage) return true; // if (isPublicChannel && isSecureMessage) return true;
//skip public messages (e.g. @player mentions) on the secure channel // //skip public messages (e.g. @player mentions) on the secure channel
if ((!isPublicChannel) && (!isSecureMessage)) return true; // if ((!isPublicChannel) && (!isSecureMessage)) return true;
//NOTE: these two are currently redundant with the above two tests - but code can change... //NOTE: these two are redundant with the above two tests in place - but things have changed...
//from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in
//both the public and private channels //both the public and private channels
//we don't include this '[secure]' text above, as it's redundant in the faction-only channel //we don't include this '[secure]' text above, as it's redundant in the faction-only channel
//let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one
if (isPublicChannel && isSecureMessage) msg = '<span style="color: #f66">[secure]</span> ' + msg; if (!systemNarrowcast && !(isPublicChannel===false) && isSecureMessage) msg = '<span style="color: #f88; background-color: #500;">[faction]</span> ' + msg;
//and, add the reverse - a 'public' marker to messages in the private channel //and, add the reverse - a 'public' marker to messages in the private channel
if ((!isPublicChannel) && (!isSecureMessage)) msg = '<span style="color: #ff6">[public]</span> ' + msg; if (!systemNarrowcast && !(isPublicChannel===true) && (!isSecureMessage)) msg = '<span style="color: #ff6; background-color: #550">[public]</span> ' + msg;
// format: timestamp, autogenerated, HTML message // format: timestamp, autogenerated, HTML message
@ -367,6 +402,7 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs) {
if(elm.is(':hidden')) return; if(elm.is(':hidden')) return;
// discard guids and sort old to new // discard guids and sort old to new
//TODO? stable sort, to preserve server message ordering? or sort by GUID if timestamps equal?
var vals = $.map(data, function(v, k) { return [v]; }); var vals = $.map(data, function(v, k) { return [v]; });
vals = vals.sort(function(a, b) { return a[0]-b[0]; }); vals = vals.sort(function(a, b) { return a[0]-b[0]; });
@ -433,7 +469,7 @@ window.chat.getActive = function() {
window.chat.tabToChannel = function(tab) { window.chat.tabToChannel = function(tab) {
if (tab == 'faction') return 'faction'; if (tab == 'faction') return 'faction';
if (tab == 'alerts') return 'alerts'; if (tab == 'alerts') return 'alerts';
return 'all'; //for 'full', 'compact' and 'public' return 'all';
}; };
@ -491,6 +527,9 @@ window.chat.request = function() {
// the 'public', 'full' and 'compact' tabs are all based off the 'public' COMM data // the 'public', 'full' and 'compact' tabs are all based off the 'public' COMM data
chat.requestPublic(false); chat.requestPublic(false);
} }
if (channel == 'alerts' || (window.chat.backgroundChannels && window.chat.backgroundChannels['alerts'])) {
chat.requestAlerts(false);
}
} }
@ -516,54 +555,60 @@ window.chat.needMoreMessages = function() {
}; };
window.chat.chooseAnchor = function(t) { window.chat.chooseTab = function(tab) {
if (tab != 'all' && tab != 'faction' && tab != 'alerts') {
console.warn('chat tab "'+t+'" requested - but only "all", "faction" and "alerts" are valid - assuming "all" wanted');
tab = 'all';
}
var oldTab = chat.getActive(); var oldTab = chat.getActive();
var oldChannel = chat.tabToChannel(oldTab);
var tt = t.text(); localStorage['iitc-chat-tab'] = tab;
localStorage['iitc-chat-tab'] = tt;
var mark = $('#chatinput mark'); var mark = $('#chatinput mark');
var input = $('#chatinput input'); var input = $('#chatinput input');
$('#chatcontrols .active').removeClass('active'); $('#chatcontrols .active').removeClass('active');
$("#chatcontrols a:contains('" + tt + "')").addClass('active'); $("#chatcontrols a:contains('" + tab + "')").addClass('active');
var newChannel = chat.tabToChannel(tt); if (tab != oldTab) startRefreshTimeout(0.1*1000); //only chat uses the refresh timer stuff, so a perfect way of forcing an early refresh after a tab change
if (newChannel != oldChannel) startRefreshTimeout(0.1*1000); //only chat uses the refresh timer stuff, so a perfect way of forcing an early refresh after a tab change
$('#chat > div').hide(); $('#chat > div').hide();
var elm; var elm;
switch(tt) { switch(tab) {
case 'faction': case 'faction':
input.css('color', ''); input.css('color', '');
mark.css('color', ''); mark.css('color', '');
mark.text('tell faction:'); mark.text('tell faction:');
chat.renderFaction(false);
break; break;
case 'public': case 'all':
input.css('cssText', 'color: #f66 !important'); input.css('cssText', 'color: #f66 !important');
mark.css('cssText', 'color: #f66 !important'); mark.css('cssText', 'color: #f66 !important');
mark.text('broadcast:'); mark.text('broadcast:');
chat.renderPublic(false);
break; break;
case 'compact': case 'alerts':
case 'full':
mark.css('cssText', 'color: #bbb !important'); mark.css('cssText', 'color: #bbb !important');
input.css('cssText', 'color: #bbb !important'); input.css('cssText', 'color: #bbb !important');
mark.text('tell Jarvis:'); mark.text('tell Jarvis:');
//chat.renderAlerts(false);
break; break;
default: default:
throw('chat.chooser was asked to handle unknown button: ' + tt); throw('chat.chooser was asked to handle unknown button: ' + tt);
} }
var elm = $('#chat' + tt); var elm = $('#chat' + tab);
elm.show(); elm.show();
eval('chat.render' + tt.capitalize() + '(false);');
if(elm.data('needsScrollTop')) { if(elm.data('needsScrollTop')) {
elm.data('ignoreNextScroll', true); elm.data('ignoreNextScroll', true);
elm.scrollTop(elm.data('needsScrollTop')); elm.scrollTop(elm.data('needsScrollTop'));
@ -577,13 +622,13 @@ window.chat.show = function(name) {
: $('#updatestatus').show(); : $('#updatestatus').show();
$('#chat, #chatinput').show(); $('#chat, #chatinput').show();
var t = $('<a>'+name+'</a>'); window.chat.chooseTab(name);
window.chat.chooseAnchor(t);
} }
window.chat.chooser = function(event) { window.chat.chooser = function(event) {
var t = $(event.target); var t = $(event.target);
window.chat.chooseAnchor(t); var tab = t.text();
window.chat.chooseTab(tab);
} }
// contains the logic to keep the correct scroll position. // contains the logic to keep the correct scroll position.
@ -614,15 +659,14 @@ window.chat.keepScrollPosition = function(box, scrollBefore, isOldMsgs) {
window.chat.setup = function() { window.chat.setup = function() {
if (localStorage['iitc-chat-tab']) { if (localStorage['iitc-chat-tab']) {
var t = $('<a>'+localStorage['iitc-chat-tab']+'</a>'); chat.chooseTab(localStorage['iitc-chat-tab']);
window.chat.chooseAnchor(t);
} }
$('#chatcontrols, #chat, #chatinput').show(); $('#chatcontrols, #chat, #chatinput').show();
$('#chatcontrols a:first').click(window.chat.toggle); $('#chatcontrols a:first').click(window.chat.toggle);
$('#chatcontrols a').each(function(ind, elm) { $('#chatcontrols a').each(function(ind, elm) {
if($.inArray($(elm).text(), ['full', 'compact', 'public', 'faction']) !== -1) if($.inArray($(elm).text(), ['all', 'faction', 'alerts']) !== -1)
$(elm).click(window.chat.chooser); $(elm).click(window.chat.chooser);
}); });
@ -641,13 +685,20 @@ window.chat.setup = function() {
if(scrollBottom(t) === 0) chat.requestFaction(false); if(scrollBottom(t) === 0) chat.requestFaction(false);
}); });
$('#chatpublic, #chatfull, #chatcompact').scroll(function() { $('#chatall').scroll(function() {
var t = $(this); var t = $(this);
if(t.data('ignoreNextScroll')) return t.data('ignoreNextScroll', false); if(t.data('ignoreNextScroll')) return t.data('ignoreNextScroll', false);
if(t.scrollTop() < CHAT_REQUEST_SCROLL_TOP) chat.requestPublic(true); if(t.scrollTop() < CHAT_REQUEST_SCROLL_TOP) chat.requestPublic(true);
if(scrollBottom(t) === 0) chat.requestPublic(false); if(scrollBottom(t) === 0) chat.requestPublic(false);
}); });
$('#chatalerts').scroll(function() {
var t = $(this);
if(t.data('ignoreNextScroll')) return t.data('ignoreNextScroll', false);
if(t.scrollTop() < CHAT_REQUEST_SCROLL_TOP) chat.requestAlerts(true);
if(scrollBottom(t) === 0) chat.requestAlerts(false);
});
window.requests.addRefreshFunction(chat.request); window.requests.addRefreshFunction(chat.request);
var cls = PLAYER.team === 'RESISTANCE' ? 'res' : 'enl'; var cls = PLAYER.team === 'RESISTANCE' ? 'res' : 'enl';
@ -708,8 +759,8 @@ window.chat.setupPosting = function() {
window.chat.postMsg = function() { window.chat.postMsg = function() {
var c = chat.getActive(); var c = chat.getActive();
if(c === 'full' || c === 'compact') if(c == 'alerts')
return alert('Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?'); return alert("Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?\n(You can't chat to the 'alerts' channel!)");
var msg = $.trim($('#chatinput input').val()); var msg = $.trim($('#chatinput input').val());
if(!msg || msg === '') return; if(!msg || msg === '') return;
@ -727,13 +778,12 @@ window.chat.postMsg = function() {
return result; return result;
} }
var publik = c === 'public';
var latlng = map.getCenter(); var latlng = map.getCenter();
var data = {message: msg, var data = {message: msg,
latE6: Math.round(latlng.lat*1E6), latE6: Math.round(latlng.lat*1E6),
lngE6: Math.round(latlng.lng*1E6), lngE6: Math.round(latlng.lng*1E6),
tab: publik ? 'all' : 'faction'}; tab: c};
var errMsg = 'Your message could not be delivered. You can copy&' + var errMsg = 'Your message could not be delivered. You can copy&' +
'paste it here and try again if you want:\n\n' + msg; 'paste it here and try again if you want:\n\n' + msg;
@ -741,7 +791,8 @@ window.chat.postMsg = function() {
window.postAjax('sendPlext', data, window.postAjax('sendPlext', data,
function(response) { function(response) {
if(response.error) alert(errMsg); if(response.error) alert(errMsg);
if(publik) chat.requestPublic(false); else chat.requestFaction(false); }, startRefreshTimeout(0.1*1000); //only chat uses the refresh timer stuff, so a perfect way of forcing an early refresh after a send message
},
function() { function() {
alert(errMsg); alert(errMsg);
} }

13
main.js
View File

@ -72,14 +72,14 @@ document.getElementsByTagName('body')[0].innerHTML = ''
+ '<div id="map">Loading, please wait</div>' + '<div id="map">Loading, please wait</div>'
+ '<div id="chatcontrols" style="display:none">' + '<div id="chatcontrols" style="display:none">'
+ '<a accesskey="0" title="[0]"><span class="toggle expand"></span></a>' + '<a accesskey="0" title="[0]"><span class="toggle expand"></span></a>'
+ '<a accesskey="1" title="[1]">full</a><a accesskey="2" title="[2]">compact</a>' + '<a accesskey="1" title="[1]">all</a>'
+ '<a accesskey="3" title="[3]">public</a><a accesskey="4" title="[4]" class="active">faction</a>' + '<a accesskey="2" title="[2]"class="active">faction</a>'
+ '<a accesskey="3" title="[3]">alerts</a>'
+ '</div>' + '</div>'
+ '<div id="chat" style="display:none">' + '<div id="chat" style="display:none">'
+ ' <div id="chatfaction"></div>' + ' <div id="chatfaction"></div>'
+ ' <div id="chatpublic"></div>' + ' <div id="chatall"></div>'
+ ' <div id="chatcompact"></div>' + ' <div id="chatalerts"></div>'
+ ' <div id="chatfull"></div>'
+ '</div>' + '</div>'
+ '<form id="chatinput" style="display:none"><table><tr>' + '<form id="chatinput" style="display:none"><table><tr>'
+ ' <td><time></time></td>' + ' <td><time></time></td>'
@ -136,9 +136,6 @@ window.MAX_IDLE_TIME = 4*60; // stop updating map after 4min idling
window.HIDDEN_SCROLLBAR_ASSUMED_WIDTH = 20; window.HIDDEN_SCROLLBAR_ASSUMED_WIDTH = 20;
window.SIDEBAR_WIDTH = 300; window.SIDEBAR_WIDTH = 300;
// how many items to request each query
window.CHAT_PUBLIC_ITEMS = 50;
window.CHAT_FACTION_ITEMS = 50;
// how many pixels to the top before requesting new data // how many pixels to the top before requesting new data
window.CHAT_REQUEST_SCROLL_TOP = 200; window.CHAT_REQUEST_SCROLL_TOP = 200;
window.CHAT_SHRINKED = 60; window.CHAT_SHRINKED = 60;

View File

@ -197,7 +197,8 @@ a:hover {
#chatcontrols a.active { #chatcontrols a.active {
border-color: #FFCE00; border-color: #FFCE00;
border-bottom-width:0px; border-bottom-width:0px;
font-weight:bold font-weight:bold;
background: rgb(8, 48, 78);1
} }
#chatcontrols a.active + a { #chatcontrols a.active + a {
@ -247,9 +248,6 @@ em {
top: 25px; top: 25px;
} }
#chatpublic, #chatfull, #chatcompact {
display: none;
}
#chat > div { #chat > div {
overflow-x:hidden; overflow-x:hidden;