kopia lustrzana https://github.com/backface/turtlestitch
DRY out creation of Costumes/Sounds/etc submenus
rodzic
f9d62c1b7f
commit
5452c2bfa7
88
gui.js
88
gui.js
|
@ -2466,6 +2466,27 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
'Costumes' : 'Backgrounds',
|
'Costumes' : 'Backgrounds',
|
||||||
shiftClicked = (world.currentKey === 16);
|
shiftClicked = (world.currentKey === 16);
|
||||||
|
|
||||||
|
// Utility for creating Costumes, etc menus.
|
||||||
|
// loadFunction takes in two parameters: a file URL, and a canonical name
|
||||||
|
function createMediaMenu (mediaType, loadFunction) {
|
||||||
|
return function () {
|
||||||
|
var names = this.getMediaList(mediaType),
|
||||||
|
mediaMenu = new MenuMorph(
|
||||||
|
myself,
|
||||||
|
localize('Import') + ' ' + localize(mediaType)
|
||||||
|
);
|
||||||
|
|
||||||
|
names.forEach(function (item) {
|
||||||
|
mediaMenu.addItem(
|
||||||
|
item.name,
|
||||||
|
function () {loadFunction(item.file, item.name); },
|
||||||
|
item.help
|
||||||
|
);
|
||||||
|
});
|
||||||
|
mediaMenu.popup(world, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
menu = new MenuMorph(this);
|
menu = new MenuMorph(this);
|
||||||
menu.addItem('Project notes...', 'editProjectNotes');
|
menu.addItem('Project notes...', 'editProjectNotes');
|
||||||
menu.addLine();
|
menu.addLine();
|
||||||
|
@ -2567,42 +2588,22 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
);
|
);
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
'Libraries...',
|
'Libraries...',
|
||||||
function () {
|
createMediaMenu(
|
||||||
// read a list of libraries from an external file,
|
'libraries',
|
||||||
// TODO: Make menu name consistent, fix URL
|
|
||||||
var libMenu = new MenuMorph(this, 'Import library'),
|
|
||||||
libraries = this.getMediaList('libraries');
|
|
||||||
|
|
||||||
function loadLib(file, name) {
|
function loadLib(file, name) {
|
||||||
var url = myself.resourceURL('libraries', file);
|
var url = myself.resourceURL('libraries', file);
|
||||||
myself.droppedText(myself.getURL(url), name);
|
myself.droppedText(myself.getURL(url), name);
|
||||||
}
|
}
|
||||||
|
),
|
||||||
libraries.forEach(function (lib) {
|
|
||||||
libMenu.addItem(
|
|
||||||
lib.name,
|
|
||||||
function () {loadLib(lib.file, lib.name) },
|
|
||||||
lib.help
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
libMenu.popup(world, pos);
|
|
||||||
},
|
|
||||||
'Select categories of additional blocks to add to this project.'
|
'Select categories of additional blocks to add to this project.'
|
||||||
);
|
);
|
||||||
|
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
localize(graphicsName) + '...',
|
localize(graphicsName) + '...',
|
||||||
function () {
|
createMediaMenu(
|
||||||
var dir = graphicsName,
|
graphicsName,
|
||||||
names = myself.getMediaList(dir),
|
function loadCostume(file, name) {
|
||||||
libMenu = new MenuMorph(
|
var url = myself.resourceURL(graphicsName, file),
|
||||||
myself,
|
|
||||||
localize('Import') + ' ' + localize(dir)
|
|
||||||
);
|
|
||||||
|
|
||||||
function loadCostume(name) {
|
|
||||||
var url = myself.resourceURL(dir, name),
|
|
||||||
img = new Image();
|
img = new Image();
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
var canvas = newCanvas(new Point(img.width, img.height));
|
var canvas = newCanvas(new Point(img.width, img.height));
|
||||||
|
@ -2611,42 +2612,21 @@ IDE_Morph.prototype.projectMenu = function () {
|
||||||
};
|
};
|
||||||
img.src = url;
|
img.src = url;
|
||||||
}
|
}
|
||||||
|
),
|
||||||
names.forEach(function (image) {
|
|
||||||
libMenu.addItem(
|
|
||||||
image.name,
|
|
||||||
function () {loadCostume(image.file); },
|
|
||||||
image.help
|
|
||||||
);
|
|
||||||
});
|
|
||||||
libMenu.popup(world, pos);
|
|
||||||
},
|
|
||||||
'Select a costume from the media library'
|
'Select a costume from the media library'
|
||||||
);
|
);
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
localize('Sounds') + '...',
|
localize('Sounds') + '...',
|
||||||
function () {
|
createMediaMenu(
|
||||||
var names = this.getMediaList('Sounds'),
|
'Sounds',
|
||||||
// TODO: Fix this menu name
|
function loadSound(file, name) {
|
||||||
libMenu = new MenuMorph(this, 'Import sound');
|
var url = myself.resourceURL('Sounds', file),
|
||||||
|
|
||||||
function loadSound(name) {
|
|
||||||
var url = myself.resourceURL('Sounds', name),
|
|
||||||
audio = new Audio();
|
audio = new Audio();
|
||||||
audio.src = url;
|
audio.src = url;
|
||||||
audio.load();
|
audio.load();
|
||||||
myself.droppedAudio(audio, name);
|
myself.droppedAudio(audio, name);
|
||||||
}
|
}
|
||||||
|
),
|
||||||
names.forEach(function (sound) {
|
|
||||||
libMenu.addItem(
|
|
||||||
sound.name,
|
|
||||||
function () {loadSound(sound.file); },
|
|
||||||
sound.help
|
|
||||||
);
|
|
||||||
});
|
|
||||||
libMenu.popup(world, pos);
|
|
||||||
},
|
|
||||||
'Select a sound from the media library'
|
'Select a sound from the media library'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue