From f1fbb38b8715639e6025c130de70ef269cb0c0cd Mon Sep 17 00:00:00 2001 From: jmoenig Date: Wed, 21 Jan 2015 10:23:02 +0100 Subject: [PATCH] Keep layering of nested sprites thru drag & drop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it used to be that dragging an anchor always brought it to the front, altering the nested sprite’s internal layering order --- history.txt | 4 ++++ objects.js | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/history.txt b/history.txt index b621772c..1880e45b 100755 --- a/history.txt +++ b/history.txt @@ -2418,3 +2418,7 @@ ______ ------ * BYOB: fixed #702 * GUI: fixed #680 + +150121 +------ +* Objects: Keep layering of nested sprites thru drag & drop diff --git a/objects.js b/objects.js index 78545a59..e59726f8 100644 --- a/objects.js +++ b/objects.js @@ -125,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2015-January-12'; +modules.objects = '2015-January-21'; var SpriteMorph; var StageMorph; @@ -1315,6 +1315,7 @@ SpriteMorph.prototype.init = function (globals) { this.anchor = null; this.nestingScale = 1; this.rotatesWithAnchor = true; + this.layers = null; // cache for dragging nested sprites, don't serialize this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) @@ -3158,6 +3159,7 @@ SpriteMorph.prototype.positionTalkBubble = function () { SpriteMorph.prototype.prepareToBeGrabbed = function (hand) { var bubble = this.talkBubble(); + this.recordLayers(); if (!bubble) {return null; } this.removeShadow(); bubble.hide(); @@ -3168,6 +3170,7 @@ SpriteMorph.prototype.prepareToBeGrabbed = function (hand) { }; SpriteMorph.prototype.justDropped = function () { + this.restoreLayers(); this.positionTalkBubble(); }; @@ -4045,6 +4048,28 @@ SpriteMorph.prototype.allAnchors = function () { return result; }; +SpriteMorph.prototype.recordLayers = function () { + var stage = this.parentThatIsA(StageMorph); + if (!stage) { + this.layerCache = null; + return; + } + this.layers = this.allParts(); + this.layers.sort(function (x, y) { + return stage.children.indexOf(x) < stage.children.indexOf(y) ? + -1 : 1; + }); +}; + +SpriteMorph.prototype.restoreLayers = function () { + if (this.layers && this.layers.length > 1) { + this.layers.forEach(function (sprite) { + sprite.comeToFront(); + }); + } + this.layers = null; +}; + // SpriteMorph highlighting SpriteMorph.prototype.addHighlight = function (oldHighlight) {