mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Merge pull request #1448 from TheSecretSquad/issue#1213CoordinateDisplayEdgeDetection
Issue#1213 coordinate display edge detection
This commit is contained in:
commit
9697af6b05
2 changed files with 44 additions and 10 deletions
|
@ -150,6 +150,12 @@ module.exports = class Camera extends CocoClass
|
||||||
#zv = Math.min(Math.max(0, worldPos.z - 5), cPos.z - 5) / (cPos.z - 5)
|
#zv = Math.min(Math.max(0, worldPos.z - 5), cPos.z - 5) / (cPos.z - 5)
|
||||||
#zv * ratioWithY + (1 - zv) * ratioWithoutY
|
#zv * ratioWithY + (1 - zv) * ratioWithoutY
|
||||||
|
|
||||||
|
distanceToTopEdge: (y) ->
|
||||||
|
@worldViewport.y - y
|
||||||
|
|
||||||
|
distanceToRightEdge: (x) ->
|
||||||
|
(@worldViewport.x + @worldViewport.width) - x
|
||||||
|
|
||||||
# SUBSCRIPTIONS
|
# SUBSCRIPTIONS
|
||||||
|
|
||||||
onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300
|
onZoomIn: (e) -> @zoomTo @target, @zoom * 1.15, 300
|
||||||
|
|
|
@ -70,36 +70,64 @@ module.exports = class CoordinateDisplay extends createjs.Container
|
||||||
contentWidth = @label.getMeasuredWidth() + (2 * margin)
|
contentWidth = @label.getMeasuredWidth() + (2 * margin)
|
||||||
contentHeight = @label.getMeasuredHeight() + (2 * margin)
|
contentHeight = @label.getMeasuredHeight() + (2 * margin)
|
||||||
|
|
||||||
# Shift all contents up so marker is at pointer (affects container cache position)
|
# Shift pointmarker up so it centers at pointer (affects container cache position)
|
||||||
@label.regY = @background.regY = @pointMarker.regY = contentHeight
|
@pointMarker.regY = contentHeight
|
||||||
|
|
||||||
pointMarkerStroke = 2
|
pointMarkerStroke = 2
|
||||||
pointMarkerLength = 8
|
pointMarkerLength = 8
|
||||||
|
fullPointMarkerLength = pointMarkerLength + (pointMarkerStroke / 2)
|
||||||
contributionsToTotalSize = []
|
contributionsToTotalSize = []
|
||||||
contributionsToTotalSize = contributionsToTotalSize.concat @updateCoordinates contentWidth, contentHeight, pointMarkerLength
|
contributionsToTotalSize = contributionsToTotalSize.concat @updateCoordinates contentWidth, contentHeight, fullPointMarkerLength
|
||||||
contributionsToTotalSize = contributionsToTotalSize.concat @updatePointMarker 0, contentHeight, pointMarkerLength, pointMarkerStroke
|
contributionsToTotalSize = contributionsToTotalSize.concat @updatePointMarker 0, contentHeight, pointMarkerLength, pointMarkerStroke
|
||||||
|
|
||||||
totalWidth = contentWidth + contributionsToTotalSize.reduce (a, b) -> a + b
|
totalWidth = contentWidth + contributionsToTotalSize.reduce (a, b) -> a + b
|
||||||
totalHeight = contentHeight + contributionsToTotalSize.reduce (a, b) -> a + b
|
totalHeight = contentHeight + contributionsToTotalSize.reduce (a, b) -> a + b
|
||||||
|
|
||||||
@cache -pointMarkerLength, -totalHeight + pointMarkerLength, totalWidth, totalHeight
|
if @isNearTopEdge()
|
||||||
|
verticalEdge =
|
||||||
|
startPos: -fullPointMarkerLength
|
||||||
|
posShift: -contentHeight + 4
|
||||||
|
else
|
||||||
|
verticalEdge =
|
||||||
|
startPos: -totalHeight + fullPointMarkerLength
|
||||||
|
posShift: contentHeight
|
||||||
|
|
||||||
updateCoordinates: (contentWidth, contentHeight, initialXYOffset) ->
|
if @isNearRightEdge()
|
||||||
offsetForPointMarker = initialXYOffset
|
horizontalEdge =
|
||||||
|
startPos: -totalWidth + fullPointMarkerLength
|
||||||
|
posShift: totalWidth
|
||||||
|
else
|
||||||
|
horizontalEdge =
|
||||||
|
startPos: -fullPointMarkerLength
|
||||||
|
posShift: 0
|
||||||
|
|
||||||
|
@orient verticalEdge, horizontalEdge, totalHeight, totalWidth
|
||||||
|
|
||||||
|
isNearTopEdge: ->
|
||||||
|
@camera.distanceToTopEdge(@lastPos.y) <= 1
|
||||||
|
|
||||||
|
isNearRightEdge: ->
|
||||||
|
@camera.distanceToRightEdge(@lastPos.x) <= 4
|
||||||
|
|
||||||
|
orient: (verticalEdge, horizontalEdge, totalHeight, totalWidth) ->
|
||||||
|
@label.regY = @background.regY = verticalEdge.posShift
|
||||||
|
@label.regX = @background.regX = horizontalEdge.posShift
|
||||||
|
@cache horizontalEdge.startPos, verticalEdge.startPos, totalWidth, totalHeight
|
||||||
|
|
||||||
|
updateCoordinates: (contentWidth, contentHeight, offset) ->
|
||||||
# Center label horizontally and vertically
|
# Center label horizontally and vertically
|
||||||
@label.x = contentWidth / 2 - (@label.getMeasuredWidth() / 2) + offsetForPointMarker
|
@label.x = contentWidth / 2 - (@label.getMeasuredWidth() / 2) + offset
|
||||||
@label.y = contentHeight / 2 - (@label.getMeasuredHeight() / 2) - offsetForPointMarker
|
@label.y = contentHeight / 2 - (@label.getMeasuredHeight() / 2) - offset
|
||||||
|
|
||||||
@background.graphics
|
@background.graphics
|
||||||
.clear()
|
.clear()
|
||||||
.beginFill('rgba(0,0,0,0.4)')
|
.beginFill('rgba(0,0,0,0.4)')
|
||||||
.beginStroke('rgba(0,0,0,0.6)')
|
.beginStroke('rgba(0,0,0,0.6)')
|
||||||
.setStrokeStyle(backgroundStroke = 1)
|
.setStrokeStyle(backgroundStroke = 1)
|
||||||
.drawRoundRect(offsetForPointMarker, -offsetForPointMarker, contentWidth, contentHeight, radius = 2.5)
|
.drawRoundRect(offset, -offset, contentWidth, contentHeight, radius = 2.5)
|
||||||
.endFill()
|
.endFill()
|
||||||
.endStroke()
|
.endStroke()
|
||||||
contributionsToTotalSize = [offsetForPointMarker, backgroundStroke]
|
contributionsToTotalSize = [offset, backgroundStroke]
|
||||||
|
|
||||||
updatePointMarker: (centerX, centerY, length, strokeSize) ->
|
updatePointMarker: (centerX, centerY, length, strokeSize) ->
|
||||||
strokeStyle = 'square'
|
strokeStyle = 'square'
|
||||||
|
|
Loading…
Reference in a new issue