summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2010-05-12 07:20:10 +0200
committerGuillaume Seguin <guillaume@segu.in>2010-05-12 07:20:10 +0200
commit9f7c64076941610fdc8bfdac8cce16dbbe49ecd8 (patch)
treeae32d4734448c9c530d2226973139330404d526d
parent1ed65c3c743b7330c7c79f8f255f1f29962f3902 (diff)
downloadsqwarea-helper-9f7c64076941610fdc8bfdac8cce16dbbe49ecd8.tar.gz
sqwarea-helper-9f7c64076941610fdc8bfdac8cce16dbbe49ecd8.tar.bz2
Major rework, show coords in tooltip
-rw-r--r--sqwarea-helper.user.js62
1 files changed, 43 insertions, 19 deletions
diff --git a/sqwarea-helper.user.js b/sqwarea-helper.user.js
index 7b505a9..1eb99b4 100644
--- a/sqwarea-helper.user.js
+++ b/sqwarea-helper.user.js
@@ -6,31 +6,55 @@
// @include http://www.sqwarea.com/Game
// ==/UserScript==
-var Map;
+(function () {
+ var Map, $;
-function sqwarea_init_wait() {
- if (typeof unsafeWindow.Map == 'undefined') {
- window.setTimeout(sqwarea_init_wait, 100);
- } else {
- Map = unsafeWindow.Map;
- sqwarea_helper_run();
+ function sqwarea_init_wait() {
+ if (typeof unsafeWindow.Map == 'undefined' || typeof unsafeWindow.$ == 'undefined') {
+ window.setTimeout(sqwarea_init_wait, 100);
+ } else {
+ Map = unsafeWindow.Map;
+ $ = unsafeWindow.$;
+ sqwarea_helper_run();
+ }
}
-}
-function sqwarea_helper_run() {
- Map.square._base_init_point = Map.square._initPoint;
- Map.square._initPoint = function(y, x, square) {
- Map.square._base_init_point (y, x, square);
- square.bind ('click', function(e) {
- if (e.ctrlKey) {
- alert ("Square coords : (x, y) = (" + x + ", " + y + ")");
- e.preventDefault();
+ function sqwarea_helper_run() {
+ Map.square._base_initPoint = Map.square._initPoint;
+ Map.square._base_mouseOver = Map.square._mouseOver;
+ Map.square._initPoint = function(y, x, square) {
+ // Add coords info alert on ctrl+click
+ Map.square._base_initPoint (y, x, square);
+ square.bind ('click', function(e) {
+ if (e.ctrlKey) {
+ alert ("Square coords : (x, y) = (" + x + ", " + y + ")");
+ e.preventDefault();
+ }
+ });
+ // Add coords info to tooltip
+ square.unbind('mouseenter mouseleave');
+ Map.square._mouseOver = function(e) {
+ Map.square._base_mouseOver.apply (square, arguments);
+ var info = Map._info;
+ info.append ('<dt>Coords:</dt><dd>(' + x + ', ' + y + ')</dd>');
+ var offset = {
+ left: (square.position().left + Map.size.width + 10),
+ top: (square.position().top + Map.size.height + 10)
+ };
+ info.css( offset );
+ // Reapply offsets
+ var groundOffset = Map._ground.offset();
+ if( ((offset.left + info.width()) >= (-groundOffset.left + Map._dim.width*Map.size.width - 50))
+ || ((offset.top + info.height()) >= (-groundOffset.top + Map._dim.height*Map.size.height - 50)) ) {
+ offset.left -= info.width() + Map.size.width + 30;
+ offset.top -= info.height() + Map.size.height + 30;
+ info.css( offset );
+ }
}
- });
+ square.hover(Map.square._mouseOver, Map.square._mouseOut);
+ }
}
-}
-(function () {
try {
sqwarea_init_wait();
} catch (e) {