Mercurial > hg > batmud > maputils
changeset 2382:32e668fec949
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Nov 2021 06:43:30 +0200 |
parents | d0262696140f |
children | 19a1b9048934 |
files | src/util.js |
diffstat | 1 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/util.js Thu Nov 04 05:23:16 2021 +0200 +++ b/src/util.js Thu Nov 04 06:43:30 2021 +0200 @@ -5,12 +5,13 @@ // var mapElem = null; +var mapDragEnable = false; +var mapDragPos = { x: 0, y: 0, mx: 0, my: 0 }; +var mapCurrPos = null; var mapCurrLoc = null; var mapScrollTimerID = -1; var mapScrollPosStart, mapScrollPosEnd; -var mapScrollIndex = 0.0, mapScrollSteps; -var mapDragEnable = false; -var mapDragPos = { x0: 0, y0: 0, mx: 0, my: 0 }, mapLocPos = mapDragPos; +var mapScrollIndex = 0.0, mapScrollSteps = 50; function mapAddEventOb(obname, evobj, evtype, evcallback) @@ -51,7 +52,7 @@ } } - return { x: xc, y: yc }; + return { x: xc, y: yc, mx: 0, my: 0 }; } @@ -86,11 +87,11 @@ function mapSetWindowPos(px, py) { const dim = mapGetWindowSize(); - mapDragPos.x0 = px - (dim.w / 2); - mapDragPos.y0 = py - (dim.h / 2); + mapDragPos.x = px - (dim.w / 2); + mapDragPos.y = py - (dim.h / 2); - mapElem.scrollLeft = mapDragPos.x0; - mapElem.scrollTop = mapDragPos.y0; + mapElem.scrollLeft = mapDragPos.x; + mapElem.scrollTop = mapDragPos.y; } @@ -150,6 +151,9 @@ { celem.classList.add("nactive"); mcelem.classList.add("nactive"); + + mapCurrLoc = newLoc; + mapCurrPos = mapFindElemCoords(celem); } // Set the active item in the location dropdown @@ -188,7 +192,7 @@ mapCurrLoc = null; } else - if (mapCurrLoc != newLoc) + if (mapCurrLoc != newLoc || mapCurrPos != mapDragPos) { var nelem = document.getElementById(newLoc); if (nelem) @@ -201,11 +205,13 @@ if (mapScrollTimerID != -1) clearInterval(mapScrollTimerID); - mapScrollPosStart = mapFindElemCoords(celem); + if (mapCurrPos != null) + mapScrollPosStart = mapCurrPos; + else + mapScrollPosStart = mapFindElemCoords(celem); + mapScrollPosEnd = mapFindElemCoords(nelem); mapScrollIndex = 0.0; - mapScrollSteps = 100; - mapScrollTimerID = setInterval(mapScrollToPos, 10); } else @@ -214,7 +220,6 @@ } mapSetActiveLocation(newLoc); - mapCurrLoc = newLoc; } } } @@ -242,8 +247,8 @@ const dx = ev.clientX - mapDragPos.mx; const dy = ev.clientY - mapDragPos.my; - mapElem.scrollLeft = mapDragPos.x0 - dx; - mapElem.scrollTop = mapDragPos.y0 - dy; + mapElem.scrollLeft = mapDragPos.x - dx; + mapElem.scrollTop = mapDragPos.y - dy; } @@ -255,8 +260,8 @@ clearInterval(mapScrollTimerID); mapDragPos = { - x0: mapElem.scrollLeft, - y0: mapElem.scrollTop, + x: mapElem.scrollLeft, + y: mapElem.scrollTop, mx: ev.clientX, my: ev.clientY, }; @@ -293,7 +298,6 @@ { mapSetPosToElem(nelem); mapSetActiveLocation(eid); - mapCurrLoc = eid; }, 50); }