Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace costume when type changed during edit #2500

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 72 additions & 31 deletions src/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2364,25 +2364,32 @@ IDE_Morph.prototype.addNewSprite = function () {

IDE_Morph.prototype.paintNewSprite = function () {
var sprite = new SpriteMorph(this.globalVariables),
cos = new Costume(),
myself = this;

cosName = sprite.newCostumeName(localize('Untitled')),
myself = this,
editor = new PaintEditorMorph(),
aWorld = this.world();
sprite.name = this.newSpriteName(sprite.name);
sprite.setCenter(this.stage.center());
this.stage.add(sprite);
this.sprites.add(sprite);
this.corral.addSprite(sprite);
this.selectSprite(sprite);
cos.edit(
this.world(),
this,
true,
function () {myself.removeSprite(sprite); },
function () {
editor.oncancel = function () { myself.removeSprite(sprite); };
editor.openIn(
aWorld,
newCanvas(StageMorph.prototype.dimensions, true),
null,
function (img, rc, shapes) {
cos = createCostume(img, cosName, rc, shapes);
aWorld.changed();
if (!(cos instanceof SVG_Costume))
cos.shrinkWrap();
sprite.wearCostume(cos, true); // don't shadow
myself.hasChangedMedia = true;
sprite.shadowAttribute('costumes');
sprite.addCostume(cos);
sprite.wearCostume(cos);
}
);
},
this);
};

IDE_Morph.prototype.newCamSprite = function () {
Expand Down Expand Up @@ -8325,11 +8332,33 @@ CostumeIconMorph.prototype.editCostume = function () {
}
}

this.object.edit(
this.world(),
this.parentThatIsA(IDE_Morph),
false // not a new costume, retain existing rotation center
);
var cosOld = this.object,
cosName = cosOld.name,
anIDE = this.parentThatIsA(IDE_Morph),
sprite = anIDE.currentSprite,
myself = this,
editor = (cosOld instanceof SVG_Costume) ? new VectorPaintEditorMorph() : new PaintEditorMorph(),
shapes = (cosOld instanceof SVG_Costume) ? cosOld.shapes : null,
aWorld = this.world();
editor.oncancel = nop;
editor.openIn(
aWorld,
cosOld.contents,
cosOld.rotationCenter,
function (img, rc, shapes) {
cos = createCostume(img, cosName, rc, shapes);
if (sprite instanceof SpriteMorph && !(cos instanceof SVG_Costume)) {
// don't shrinkwrap stage costumes
cos.shrinkWrap();
}
sprite.replaceCostume(cosOld, cos);
sprite.wearCostume(cos, true); // don't shadow
sprite.shadowAttribute('costumes');
aWorld.changed();
anIDE.hasChangedMedia = true;
},
anIDE,
shapes);
};

CostumeIconMorph.prototype.editRotationPointOnly = function () {
Expand Down Expand Up @@ -8792,20 +8821,32 @@ WardrobeMorph.prototype.removeCostumeAt = function (idx) {
};

WardrobeMorph.prototype.paintNew = function () {
var cos = new Costume(
newCanvas(null, true),
this.sprite.newCostumeName(localize('Untitled'))
),
ide = this.parentThatIsA(IDE_Morph),
myself = this;
cos.edit(this.world(), ide, true, null, function () {
myself.sprite.shadowAttribute('costumes');
myself.sprite.addCostume(cos);
myself.updateList();
if (ide) {
ide.currentSprite.wearCostume(cos);
}
});
var cosName = this.sprite.newCostumeName(localize('Untitled')),
anIDE = this.parentThatIsA(IDE_Morph),
myself = this,
editor = new PaintEditorMorph(),
aWorld = this.world();
editor.oncancel = nop;
editor.openIn(
aWorld,
newCanvas(StageMorph.prototype.dimensions, true),
null,
function (img, rc, shapes) {
cos = createCostume(img, cosName, rc, shapes);
aWorld.changed();
if (anIDE) {
if (anIDE.currentSprite instanceof SpriteMorph && !(cos instanceof SVG_Costume)) {
// don't shrinkwrap stage costumes
cos.shrinkWrap();
}
anIDE.currentSprite.wearCostume(cos, true); // don't shadow
anIDE.hasChangedMedia = true;
}
myself.sprite.shadowAttribute('costumes');
myself.sprite.addCostume(cos);
myself.updateList();
},
anIDE);
};

WardrobeMorph.prototype.newFromCam = function () {
Expand Down
Loading