From c05780de4ca18bc1006ffffcd45c946c781d047f Mon Sep 17 00:00:00 2001 From: Jayant Jain Date: Wed, 21 May 2014 04:50:24 +0530 Subject: [PATCH] Resolves #170, thang can be directly placed by dragging onto the map --- app/lib/surface/Surface.coffee | 7 +++++++ app/views/editor/level/thangs_tab_view.coffee | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/lib/surface/Surface.coffee b/app/lib/surface/Surface.coffee index 14e3cf15e..beb223045 100644 --- a/app/lib/surface/Surface.coffee +++ b/app/lib/surface/Surface.coffee @@ -103,6 +103,7 @@ module.exports = Surface = class Surface extends CocoClass @stage.removeAllChildren() @stage.removeEventListener 'stagemousemove', @onMouseMove @stage.removeEventListener 'stagemousedown', @onMouseDown + @stage.removeEventListener 'stagemouseup', @onMouseUp @stage.removeAllEventListeners() @stage.enableDOMEvents false @stage.enableMouseOver 0 @@ -416,6 +417,7 @@ module.exports = Surface = class Surface extends CocoClass @stage.enableMouseOver(10) @stage.addEventListener 'stagemousemove', @onMouseMove @stage.addEventListener 'stagemousedown', @onMouseDown + @stage.addEventListener 'stagemouseup', @onMouseUp @canvas.on 'mousewheel', @onMouseWheel @hookUpChooseControls() if @options.choosing createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED @@ -539,6 +541,11 @@ module.exports = Surface = class Surface extends CocoClass onBackground = not @stage.hitTest e.stageX, e.stageY Backbone.Mediator.publish 'surface:stage-mouse-down', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e + onMouseUp: (e) => + return if @disabled + onBackground = not @stage.hitTest e.stageX, e.stageY + Backbone.Mediator.publish 'surface:stage-mouse-up', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e + onMouseWheel: (e) => # https://github.com/brandonaaron/jquery-mousewheel e.preventDefault() diff --git a/app/views/editor/level/thangs_tab_view.coffee b/app/views/editor/level/thangs_tab_view.coffee index 436fbaf73..225b75901 100644 --- a/app/views/editor/level/thangs_tab_view.coffee +++ b/app/views/editor/level/thangs_tab_view.coffee @@ -43,7 +43,7 @@ module.exports = class ThangsTabView extends View 'sprite:dragged': 'onSpriteDragged' 'sprite:mouse-up': 'onSpriteMouseUp' 'sprite:double-clicked': 'onSpriteDoubleClicked' - 'surface:stage-mouse-down': 'onStageMouseDown' + 'surface:stage-mouse-up': 'onStageMouseUp' events: 'click #extant-thangs-filter button': 'onFilterExtantThangs' @@ -108,7 +108,7 @@ module.exports = class ThangsTabView extends View afterRender: -> super() return unless @supermodel.finished() - $('.tab-content').click @selectAddThang + $('.tab-content').mousedown @selectAddThang $('#thangs-list').bind 'mousewheel', @preventBodyScrollingInThangList @$el.find('#extant-thangs-filter button:first').button('toggle') $(window).resize @onWindowResize @@ -185,7 +185,7 @@ module.exports = class ThangsTabView extends View if e.originalEvent.nativeEvent.button == 2 @onSpriteContextMenu e - onStageMouseDown: (e) -> + onStageMouseUp: (e) -> if @addThangSprite # If we click on the background, we need to add @addThangSprite, but not if onSpriteMouseDown will fire. @backgroundAddClickTimeout = _.defer => @onExtantThangSelected {}