2011-02-17 20:08:50 +01:00
|
|
|
"use strict";
|
2011-01-15 02:11:31 +01:00
|
|
|
//if (!console) console = { log: function() {} };
|
2011-01-10 23:58:39 +01:00
|
|
|
|
2011-02-06 15:09:15 +01:00
|
|
|
var maptypes = {};
|
2011-02-15 13:50:04 +01:00
|
|
|
var clocks = {};
|
2011-02-06 15:09:15 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
function splitArgs(s) {
|
|
|
|
var r = s.split(' ');
|
|
|
|
delete arguments[0];
|
|
|
|
var obj = {};
|
|
|
|
var index = 0;
|
2011-01-15 02:11:31 +01:00
|
|
|
$.each(arguments, function(argumentIndex, argument) {
|
|
|
|
if (!argumentIndex) return;
|
2011-01-14 20:08:23 +01:00
|
|
|
var value = r[argumentIndex-1];
|
|
|
|
obj[argument] = value;
|
2011-01-15 02:11:31 +01:00
|
|
|
});
|
2011-01-14 20:08:23 +01:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
function swtch(value, options, defaultOption) {
|
|
|
|
return (options[value] || defaultOption)(value);
|
|
|
|
}
|
|
|
|
|
2011-01-12 01:28:45 +01:00
|
|
|
function DynMapType() { }
|
|
|
|
DynMapType.prototype = {
|
|
|
|
onTileUpdated: function(tile, tileName) {
|
2011-01-14 20:08:23 +01:00
|
|
|
var src = this.dynmap.getTileUrl(tileName);
|
2011-01-12 01:28:45 +01:00
|
|
|
tile.attr('src', src);
|
|
|
|
tile.show();
|
2011-02-17 20:08:50 +01:00
|
|
|
},
|
|
|
|
updateTileSize: function(zoom) {}
|
2011-01-12 01:28:45 +01:00
|
|
|
};
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
function DynMap(options) {
|
2011-02-01 15:16:54 +01:00
|
|
|
var me = this;
|
|
|
|
me.options = options;
|
|
|
|
$.getJSON(me.options.updateUrl + 'configuration', function(configuration) {
|
|
|
|
me.configure(configuration);
|
|
|
|
me.initialize();
|
2011-02-01 14:17:08 +01:00
|
|
|
})
|
2010-12-31 13:33:51 +01:00
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
DynMap.prototype = {
|
2011-02-17 20:08:50 +01:00
|
|
|
worlds: {},
|
2011-01-14 20:08:23 +01:00
|
|
|
registeredTiles: new Array(),
|
|
|
|
markers: new Array(),
|
2011-01-26 00:10:42 +01:00
|
|
|
chatPopups: new Array(),
|
2011-01-14 20:08:23 +01:00
|
|
|
lasttimestamp: '0',
|
|
|
|
followingPlayer: '',
|
2011-02-01 14:17:08 +01:00
|
|
|
configure: function(configuration) {
|
2011-02-01 15:16:54 +01:00
|
|
|
var me = this;
|
|
|
|
$.extend(me.options, configuration);
|
2011-02-17 20:08:50 +01:00
|
|
|
|
|
|
|
$.each(me.options.worlds, function(index, worldentry) {
|
|
|
|
var world = me.worlds[worldentry.name] = $.extend({}, worldentry, {
|
|
|
|
maps: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
$.each(worldentry.maps, function(index, mapentry) {
|
|
|
|
var map = $.extend({}, mapentry, {
|
|
|
|
world: world,
|
|
|
|
dynmap: me
|
|
|
|
});
|
|
|
|
map = world.maps[mapentry.name] = maptypes[mapentry.type](map);
|
|
|
|
|
|
|
|
world.defaultmap = world.defaultmap || map;
|
|
|
|
});
|
|
|
|
me.defaultworld = me.defaultworld || world;
|
2011-02-01 14:17:08 +01:00
|
|
|
});
|
|
|
|
},
|
2011-01-14 20:08:23 +01:00
|
|
|
initialize: function() {
|
|
|
|
var me = this;
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var container = $(me.options.container);
|
2011-02-17 20:08:50 +01:00
|
|
|
container.addClass('dynmap');
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
var mapContainer;
|
|
|
|
(mapContainer = $('<div/>'))
|
|
|
|
.addClass('map')
|
|
|
|
.appendTo(container);
|
|
|
|
|
|
|
|
var map = this.map = new google.maps.Map(mapContainer.get(0), {
|
|
|
|
zoom: 1,
|
|
|
|
center: new google.maps.LatLng(0, 1),
|
|
|
|
navigationControl: true,
|
|
|
|
navigationControlOptions: {
|
|
|
|
style: google.maps.NavigationControlStyle.DEFAULT
|
|
|
|
},
|
|
|
|
scaleControl: false,
|
|
|
|
mapTypeControl: false,
|
|
|
|
streetViewControl: false,
|
2011-01-23 12:00:15 +01:00
|
|
|
backgroundColor: 'none'
|
2011-01-14 20:08:23 +01:00
|
|
|
});
|
2011-02-17 20:08:50 +01:00
|
|
|
|
|
|
|
map.zoom_changed = function() {
|
|
|
|
me.maptype.updateTileSize(me.map.zoom);
|
|
|
|
};
|
2011-01-12 01:45:56 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
google.maps.event.addListener(map, 'dragstart', function(mEvent) {
|
|
|
|
me.followPlayer('');
|
|
|
|
});
|
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/*google.maps.event.addListener(map, 'zoom_changed', function() {
|
|
|
|
me.updateLink();
|
|
|
|
});
|
|
|
|
google.maps.event.addListener(map, 'center_changed', function() {
|
|
|
|
me.updateLink();
|
|
|
|
});*/
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
// Sidebar
|
2011-01-14 20:08:23 +01:00
|
|
|
var sidebar = me.sidebar = $('<div/>')
|
|
|
|
.addClass('sidebar')
|
|
|
|
.appendTo(container);
|
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
var panel = $('<div/>')
|
|
|
|
.addClass('panel')
|
2011-02-13 01:19:47 +01:00
|
|
|
.appendTo(sidebar);
|
|
|
|
|
2011-02-18 00:07:59 +01:00
|
|
|
// Pin button.
|
|
|
|
var pinbutton = $('<div/>')
|
|
|
|
.addClass('pin')
|
|
|
|
.click(function() {
|
|
|
|
sidebar.toggleClass('pinned');
|
|
|
|
})
|
|
|
|
.appendTo(panel);
|
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
// Worlds
|
|
|
|
var worldlist;
|
|
|
|
$('<fieldset/>')
|
|
|
|
.append($('<legend/>').text('Map Types'))
|
|
|
|
.append(me.worldlist = worldlist = $('<ul/>').addClass('worldlist'))
|
|
|
|
.appendTo(panel);
|
|
|
|
|
|
|
|
$.each(me.worlds, function(index, world) {
|
|
|
|
var maplist;
|
|
|
|
world.element = $('<li/>')
|
|
|
|
.addClass('world')
|
|
|
|
.text(world.title)
|
|
|
|
.append(maplist = $('<ul/>')
|
|
|
|
.addClass('maplist')
|
2011-02-13 01:19:47 +01:00
|
|
|
)
|
2011-02-17 20:08:50 +01:00
|
|
|
.data('world', world)
|
2011-02-13 01:19:47 +01:00
|
|
|
.appendTo(worldlist);
|
2011-01-12 01:45:56 +01:00
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
$.each(world.maps, function(index, map) {
|
|
|
|
me.map.mapTypes.set(map.world.name + '.' + map.name, map);
|
|
|
|
|
|
|
|
map.element = $('<li/>')
|
|
|
|
.addClass('map')
|
|
|
|
.append($('<a/>')
|
|
|
|
.attr({ title: map.title, href: '#' })
|
|
|
|
.addClass('maptype')
|
|
|
|
.css({ backgroundImage: 'url(' + (map.icon || 'block_' + map.name + '.png') + ')' })
|
|
|
|
.text(map.title)
|
|
|
|
)
|
|
|
|
.click(function() {
|
|
|
|
me.selectMap(map);
|
2011-01-12 01:45:56 +01:00
|
|
|
})
|
2011-02-17 20:08:50 +01:00
|
|
|
.data('map', map)
|
|
|
|
.appendTo(maplist);
|
|
|
|
});
|
2011-01-14 20:08:23 +01:00
|
|
|
});
|
2011-02-17 20:08:50 +01:00
|
|
|
|
2011-02-19 20:51:21 +01:00
|
|
|
// The clock
|
|
|
|
var largeclock = $('<div/>')
|
|
|
|
.addClass('largeclock')
|
|
|
|
.appendTo(container);
|
|
|
|
var clock = me.clock = clocks['timeofday'](
|
|
|
|
$('<div/>')
|
|
|
|
.appendTo(largeclock)
|
|
|
|
);
|
|
|
|
var clockdigital = me.clockdigital = clocks['digital'](
|
|
|
|
$('<div/>')
|
|
|
|
.appendTo(largeclock)
|
|
|
|
);
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
// The Player List
|
2011-02-17 20:08:50 +01:00
|
|
|
var playerlist;
|
|
|
|
$('<fieldset/>')
|
|
|
|
.append($('<legend/>').text('Players'))
|
|
|
|
.append(me.playerlist = playerlist = $('<ul/>').addClass('playerlist'))
|
|
|
|
.appendTo(panel);
|
2011-01-14 20:08:23 +01:00
|
|
|
|
2011-02-13 07:25:28 +01:00
|
|
|
// The Compass
|
2011-02-20 01:58:53 +01:00
|
|
|
var compass = $('<div/>')
|
|
|
|
.addClass('compass')
|
|
|
|
.appendTo(container)
|
2011-02-13 07:25:28 +01:00
|
|
|
|
2011-02-18 07:08:29 +01:00
|
|
|
// The chat
|
|
|
|
if (me.options.showchat == 'modal') {
|
|
|
|
var chat = me.chat = $('<div/>')
|
|
|
|
.addClass('chat')
|
|
|
|
.appendTo(container);
|
|
|
|
var messagelist = me.messagelist = $('<div/>')
|
|
|
|
.addClass('messagelist')
|
|
|
|
.appendTo(chat);
|
|
|
|
var chatinput = me.chatinput = $('<input/>')
|
|
|
|
.addClass('chatinput')
|
|
|
|
.attr({
|
|
|
|
id: 'chatinput',
|
|
|
|
type: 'text',
|
2011-02-20 02:02:45 +01:00
|
|
|
value: ''
|
2011-02-18 07:08:29 +01:00
|
|
|
})
|
2011-02-18 10:21:55 +01:00
|
|
|
.keydown(function(event) {
|
|
|
|
if (event.keyCode == '13') {
|
|
|
|
event.preventDefault();
|
2011-02-19 21:16:14 +01:00
|
|
|
sendChat(chatinput.val());
|
|
|
|
chatinput.val('');
|
2011-02-18 10:21:55 +01:00
|
|
|
}
|
|
|
|
})
|
2011-02-18 07:08:29 +01:00
|
|
|
.appendTo(chat);
|
|
|
|
}
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/*
|
|
|
|
var link;
|
|
|
|
var linkbox = me.linkbox = $('<div/>')
|
|
|
|
.addClass('linkbox')
|
|
|
|
.append(link=$('<input type="text" />'))
|
|
|
|
.data('link', link)
|
|
|
|
.appendTo(container);*/
|
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
$('<div/>')
|
|
|
|
.addClass('hitbar')
|
|
|
|
.appendTo(panel);
|
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var alertbox = me.alertbox = $('<div/>')
|
|
|
|
.addClass('alertbox')
|
|
|
|
.appendTo(container);
|
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
me.selectMap(me.defaultworld.defaultmap);
|
|
|
|
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-01-14 20:08:23 +01:00
|
|
|
},
|
2011-02-17 20:08:50 +01:00
|
|
|
selectMap: function(map) {
|
2011-02-18 00:07:59 +01:00
|
|
|
if (!map) { throw "Cannot select map " + map; }
|
2011-02-17 20:08:50 +01:00
|
|
|
var me = this;
|
|
|
|
me.map.setMapTypeId('none');
|
|
|
|
me.world = map.world;
|
|
|
|
me.maptype = map;
|
|
|
|
me.maptype.updateTileSize(me.map.zoom);
|
|
|
|
window.setTimeout(function() {
|
|
|
|
me.map.setMapTypeId(map.world.name + '.' + map.name);
|
|
|
|
}, 1);
|
|
|
|
$('.map', me.worldlist).removeClass('selected');
|
|
|
|
$(map.element).addClass('selected');
|
|
|
|
},
|
2011-01-14 20:08:23 +01:00
|
|
|
update: function() {
|
|
|
|
var me = this;
|
2011-01-26 00:10:42 +01:00
|
|
|
|
|
|
|
// TODO: is there a better place for this?
|
|
|
|
this.cleanPopups();
|
|
|
|
|
2011-02-17 20:08:50 +01:00
|
|
|
$.getJSON(me.options.updateUrl + "world/" + me.world.name + "/" + me.lasttimestamp, function(update) {
|
2011-01-14 20:08:23 +01:00
|
|
|
me.alertbox.hide();
|
2011-02-06 03:00:51 +01:00
|
|
|
|
|
|
|
me.lasttimestamp = update.timestamp;
|
2011-02-14 00:01:20 +01:00
|
|
|
me.clock.setTime(update.servertime);
|
2011-02-19 20:51:21 +01:00
|
|
|
me.clockdigital.setTime(update.servertime);
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-01-14 20:08:23 +01:00
|
|
|
var typeVisibleMap = {};
|
|
|
|
var newmarkers = {};
|
|
|
|
|
2011-02-06 03:00:51 +01:00
|
|
|
$.each(update.players, function(index, player) {
|
|
|
|
var mi = {
|
|
|
|
id: 'player_' + player.name,
|
|
|
|
text: player.name,
|
|
|
|
type: 'player',
|
|
|
|
position: me.map.getProjection().fromWorldToLatLng(parseFloat(player.x), parseFloat(player.y), parseFloat(player.z)),
|
|
|
|
visible: true
|
|
|
|
};
|
2010-12-31 13:33:51 +01:00
|
|
|
|
2011-02-06 03:00:51 +01:00
|
|
|
me.updateMarker(mi);
|
|
|
|
newmarkers[mi.id] = mi;
|
|
|
|
});
|
|
|
|
|
|
|
|
$.each(update.updates, function(index, update) {
|
|
|
|
swtch(update.type, {
|
2011-01-14 20:08:23 +01:00
|
|
|
tile: function() {
|
2011-02-06 03:00:51 +01:00
|
|
|
me.onTileUpdated(update.name);
|
|
|
|
},
|
|
|
|
chat: function() {
|
2011-02-18 07:08:29 +01:00
|
|
|
if (!me.options.showchat)
|
2011-02-01 15:16:54 +01:00
|
|
|
return;
|
2011-02-06 03:00:51 +01:00
|
|
|
me.onPlayerChat(update.playerName, update.message);
|
2011-02-19 16:31:13 +01:00
|
|
|
},
|
|
|
|
webchat: function() {
|
|
|
|
if (!me.options.showchat)
|
|
|
|
return;
|
2011-02-19 20:51:21 +01:00
|
|
|
me.onPlayerChat('[WEB]' + update.playerName, update.message);
|
2011-01-25 23:03:27 +01:00
|
|
|
}
|
2011-02-06 03:00:51 +01:00
|
|
|
}, function(type) {
|
|
|
|
console.log('Unknown type ', value, '!');
|
2011-01-14 20:08:23 +01:00
|
|
|
});
|
2011-02-20 01:58:53 +01:00
|
|
|
/* remove older messages from chat*/
|
|
|
|
//var timestamp = event.timeStamp;
|
|
|
|
//var divs = $('div[rel]');
|
|
|
|
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
|
2011-02-06 03:00:51 +01:00
|
|
|
});
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
for(var m in me.markers) {
|
|
|
|
var marker = me.markers[m];
|
|
|
|
if(!(m in newmarkers)) {
|
|
|
|
marker.remove(null);
|
2011-02-18 01:28:58 +01:00
|
|
|
if (marker.playerItem) {
|
|
|
|
marker.playerItem.remove();
|
2011-01-14 20:08:23 +01:00
|
|
|
}
|
|
|
|
delete me.markers[m];
|
|
|
|
}
|
|
|
|
}
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-02-06 03:00:51 +01:00
|
|
|
}, function(request, statusText, ex) {
|
2011-01-14 20:08:23 +01:00
|
|
|
me.alertbox
|
|
|
|
.text('Could not update map')
|
|
|
|
.show();
|
2011-02-01 15:16:54 +01:00
|
|
|
setTimeout(function() { me.update(); }, me.options.updaterate);
|
2011-01-14 20:08:23 +01:00
|
|
|
}
|
2011-02-06 03:00:51 +01:00
|
|
|
);
|
2011-01-14 20:08:23 +01:00
|
|
|
},
|
2011-02-17 20:08:50 +01:00
|
|
|
getTileUrl: function(tileName, always) {
|
|
|
|
var me = this;
|
|
|
|
var tile = me.registeredTiles[tileName];
|
|
|
|
|
|
|
|
if(tile) {
|
|
|
|
return me.options.tileUrl + me.world.name + '/' + tileName + '?' + tile.lastseen;
|
|
|
|
} else {
|
|
|
|
return me.options.tileUrl + me.world.name + '/' + tileName + '?0';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
registerTile: function(mapType, tileName, tile) {
|
|
|
|
this.registeredTiles[tileName] = {
|
|
|
|
tileElement: tile,
|
|
|
|
mapType: mapType,
|
|
|
|
lastseen: '0'
|
|
|
|
};
|
|
|
|
},
|
|
|
|
unregisterTile: function(mapType, tileName) {
|
|
|
|
delete this.registeredTiles[tileName];
|
|
|
|
},
|
2011-01-26 00:10:42 +01:00
|
|
|
cleanPopups: function() {
|
|
|
|
var POPUP_LIFE = 8000;
|
|
|
|
var d = new Date();
|
|
|
|
var now = d.getTime();
|
|
|
|
for (var popupIndex in this.chatPopups)
|
|
|
|
{
|
|
|
|
var popup = this.chatPopups[popupIndex];
|
|
|
|
if (now - popup.popupTime > POPUP_LIFE)
|
|
|
|
{
|
|
|
|
popup.infoWindow.close();
|
|
|
|
popup.infoWindow = null;
|
2011-01-26 01:05:00 +01:00
|
|
|
delete this.chatPopups[popupIndex];
|
2011-01-26 00:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-01-25 23:03:27 +01:00
|
|
|
onPlayerChat: function(playerName, message) {
|
|
|
|
var me = this;
|
|
|
|
var markers = me.markers;
|
2011-01-26 00:10:42 +01:00
|
|
|
var chatPopups = this.chatPopups;
|
2011-01-25 23:03:27 +01:00
|
|
|
var map = me.map;
|
|
|
|
var mid = "player_" + playerName;
|
|
|
|
var playerMarker = markers[mid];
|
2011-02-18 07:08:29 +01:00
|
|
|
if (me.options.showchat == 'balloons') {
|
|
|
|
if (playerMarker)
|
2011-01-26 00:10:42 +01:00
|
|
|
{
|
2011-02-18 07:08:29 +01:00
|
|
|
var popup = chatPopups[playerName];
|
|
|
|
if (!popup)
|
|
|
|
popup = { lines: [ message ] };
|
|
|
|
else
|
|
|
|
popup.lines[popup.lines.length] = message;
|
|
|
|
|
|
|
|
var MAX_LINES = 5;
|
|
|
|
if (popup.lines.length > MAX_LINES)
|
|
|
|
{
|
|
|
|
popup.lines = popup.lines.slice(1);
|
|
|
|
}
|
|
|
|
htmlMessage = '<div id="content"><b>' + playerName + "</b><br/><br/>"
|
|
|
|
for (var line in popup.lines)
|
|
|
|
{
|
|
|
|
htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
|
|
|
|
}
|
|
|
|
htmlMessage = htmlMessage + "</div>"
|
|
|
|
var now = new Date();
|
|
|
|
popup.popupTime = now.getTime();
|
|
|
|
if (!popup.infoWindow) {
|
|
|
|
popup.infoWindow = new google.maps.InfoWindow({
|
|
|
|
disableAutoPan: !(me.options.focuschatballoons || false),
|
|
|
|
content: htmlMessage
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
popup.infoWindow.setContent(htmlMessage);
|
|
|
|
}
|
|
|
|
popup.infoWindow.open(map, playerMarker);
|
|
|
|
this.chatPopups[playerName] = popup;
|
2011-01-26 00:10:42 +01:00
|
|
|
}
|
2011-02-18 07:08:29 +01:00
|
|
|
} else if (me.options.showchat == 'modal') {
|
|
|
|
var me = this;
|
|
|
|
var messagelist = me.messagelist;
|
2011-02-20 01:58:53 +01:00
|
|
|
var timestamp = event.timeStamp;
|
2011-02-18 07:08:29 +01:00
|
|
|
|
|
|
|
var messageRow = $('<div/>')
|
|
|
|
.addClass('messagerow')
|
2011-02-20 01:58:53 +01:00
|
|
|
.attr({ "rel": timestamp})
|
2011-02-18 07:08:29 +01:00
|
|
|
|
|
|
|
var playerIconContainer = $('<span/>')
|
|
|
|
.addClass('messageicon')
|
|
|
|
|
|
|
|
if (me.options.showplayerfacesinmenu) {
|
|
|
|
getMinecraftHead(playerName, 16, function(head) {
|
|
|
|
messageRow.icon = $(head)
|
|
|
|
.addClass('playerIcon')
|
|
|
|
.appendTo(playerIconContainer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playerName != 'Server') {
|
|
|
|
var playerWorldContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text('['+me.world+']')
|
|
|
|
|
|
|
|
var playerGroupContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text('[Group]')
|
2011-01-26 01:05:00 +01:00
|
|
|
}
|
2011-02-18 07:08:29 +01:00
|
|
|
|
|
|
|
var playerNameContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text(' '+playerName+': ')
|
|
|
|
|
|
|
|
var playerMessageContainer = $('<span/>')
|
|
|
|
.addClass('messagetext')
|
|
|
|
.text(message)
|
|
|
|
|
|
|
|
messageRow.append(playerIconContainer,playerNameContainer,playerMessageContainer);
|
|
|
|
//messageRow.append(playerIconContainer,playerWorldContainer,playerGroupContainer,playerNameContainer,playerMessageContainer);
|
2011-02-20 01:58:53 +01:00
|
|
|
setTimeout(function() { messageRow.remove(); }, me.options.messagettl);
|
2011-02-18 07:08:29 +01:00
|
|
|
messagelist.append(messageRow);
|
|
|
|
|
|
|
|
me.messagelist.show();
|
|
|
|
//var scrollHeight = jQuery(me.messagelist).attr('scrollHeight');
|
|
|
|
var scrollHeight = me.messagelist[0].scrollHeight;
|
|
|
|
messagelist.scrollTop(scrollHeight);
|
2011-01-25 23:03:27 +01:00
|
|
|
}
|
|
|
|
},
|
2011-01-14 20:08:23 +01:00
|
|
|
onTileUpdated: function(tileName) {
|
|
|
|
var me = this;
|
|
|
|
var tile = this.registeredTiles[tileName];
|
|
|
|
|
|
|
|
if (tile) {
|
|
|
|
tile.lastseen = this.lasttimestamp;
|
|
|
|
tile.mapType.onTileUpdated(tile.tileElement, tileName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateMarker: function(mi) {
|
|
|
|
var me = this;
|
|
|
|
var markers = me.markers;
|
|
|
|
var map = me.map;
|
|
|
|
|
|
|
|
if(mi.id in markers) {
|
|
|
|
var m = markers[mi.id];
|
|
|
|
m.toggle(mi.visible);
|
|
|
|
m.setPosition(mi.position);
|
|
|
|
} else {
|
|
|
|
var contentfun = function(div,mi) {
|
|
|
|
$(div)
|
|
|
|
.addClass('Marker')
|
|
|
|
.addClass(mi.type + 'Marker')
|
|
|
|
.append($('<img/>').attr({src: mi.type + '.png'}))
|
|
|
|
.append($('<span/>').text(mi.text));
|
|
|
|
};
|
|
|
|
if (mi.type == 'player') {
|
|
|
|
contentfun = function(div, mi) {
|
2011-01-15 02:11:31 +01:00
|
|
|
var playerImage;
|
2011-01-14 20:08:23 +01:00
|
|
|
$(div)
|
|
|
|
.addClass('Marker')
|
|
|
|
.addClass('playerMarker')
|
2011-01-15 02:11:31 +01:00
|
|
|
.append(playerImage = $('<img/>')
|
|
|
|
.attr({ src: 'player.png' }))
|
2011-01-14 20:08:23 +01:00
|
|
|
.append($('<span/>')
|
|
|
|
.addClass('playerName')
|
2011-01-15 02:11:31 +01:00
|
|
|
.text(mi.text))
|
2011-02-01 15:16:54 +01:00
|
|
|
if (me.options.showplayerfacesonmap) {
|
|
|
|
getMinecraftHead(mi.text, 32, function(head) {
|
|
|
|
$(head)
|
2011-02-17 20:08:50 +01:00
|
|
|
.addClass('playericon')
|
2011-02-01 15:16:54 +01:00
|
|
|
.prependTo(div);
|
|
|
|
playerImage.remove();
|
|
|
|
});
|
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
var marker = new CustomMarker(mi.position, map, contentfun, mi);
|
|
|
|
marker.markerType = mi.type;
|
|
|
|
|
|
|
|
markers[mi.id] = marker;
|
|
|
|
|
|
|
|
if (mi.type == 'player') {
|
2011-02-17 20:08:50 +01:00
|
|
|
marker.playerItem = $('<li/>')
|
|
|
|
.addClass('player')
|
|
|
|
.append(marker.playerIconContainer = $('<span/>')
|
|
|
|
.addClass('playerIcon')
|
|
|
|
.append($('<img/>').attr({ src: 'player_face.png' }))
|
|
|
|
.attr({ title: 'Follow ' + mi.text })
|
|
|
|
.click(function() {
|
|
|
|
var follow = mi.id != me.followingPlayer;
|
|
|
|
me.followPlayer(follow ? mi.id : '')
|
|
|
|
}))
|
2011-01-14 20:08:23 +01:00
|
|
|
.append($('<a/>')
|
2011-02-17 20:08:50 +01:00
|
|
|
.attr({
|
|
|
|
href: '#',
|
|
|
|
title: 'Center on ' + mi.text
|
|
|
|
})
|
|
|
|
.text(mi.text)
|
|
|
|
)
|
|
|
|
.click(function(e) { map.panTo(markers[mi.id].getPosition()); })
|
|
|
|
.appendTo(me.playerlist);
|
2011-01-14 20:08:23 +01:00
|
|
|
|
2011-02-01 15:16:54 +01:00
|
|
|
if (me.options.showplayerfacesinmenu) {
|
|
|
|
getMinecraftHead(mi.text, 16, function(head) {
|
2011-02-17 20:08:50 +01:00
|
|
|
$('img', marker.playerIconContainer).remove();
|
|
|
|
marker.playerItem.icon = $(head)
|
2011-02-01 15:16:54 +01:00
|
|
|
.appendTo(marker.playerIconContainer);
|
|
|
|
});
|
|
|
|
}
|
2011-01-14 20:08:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mi.id == me.followingPlayer) {
|
|
|
|
map.panTo(markers[mi.id].getPosition());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
followPlayer: function(name) {
|
|
|
|
var me = this;
|
2011-02-17 20:08:50 +01:00
|
|
|
$('.following', me.playerlist).removeClass('following');
|
2011-01-14 20:08:23 +01:00
|
|
|
|
|
|
|
var m = me.markers[name];
|
|
|
|
if(m) {
|
2011-02-17 20:08:50 +01:00
|
|
|
$(m.playerItem).addClass('following');
|
2011-01-14 20:08:23 +01:00
|
|
|
me.map.panTo(m.getPosition());
|
|
|
|
}
|
|
|
|
this.followingPlayer = name;
|
|
|
|
},
|
|
|
|
// TODO: Enable hash-links.
|
|
|
|
/* updateLink: function() {
|
|
|
|
var me = this;
|
|
|
|
var url = location.href.match(/^[^#]+/);
|
|
|
|
|
|
|
|
var a=url
|
|
|
|
+ "#lat=" + me.map.getCenter().lat().toFixed(6)
|
|
|
|
+ "&lng=" + me.map.getCenter().lng().toFixed(6)
|
|
|
|
+ "&zoom=" + me.map.getZoom();
|
|
|
|
me.linkbox.data('link').val(a);
|
|
|
|
}*/
|
|
|
|
}
|