mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-18 15:26:19 +08:00
Add some reference image options
This commit is contained in:
parent
6d60649e0c
commit
637fa66e2e
42
js/api.js
42
js/api.js
@ -268,23 +268,6 @@ const Blockbench = {
|
||||
},
|
||||
//Events
|
||||
dispatchEvent(event_name, data) {
|
||||
return EventSystem.prototype.dispatchEvent.call(this, event_name, data);
|
||||
},
|
||||
on(event_name, cb) {
|
||||
console.log(event_name, this)
|
||||
return EventSystem.prototype.on.call(this, event_name, cb);
|
||||
},
|
||||
once(event_name, cb) {
|
||||
return EventSystem.prototype.once.call(this, event_name, cb);
|
||||
},
|
||||
addListener(event_name, cb) {
|
||||
return EventSystem.prototype.addListener.call(this, event_name, cb);
|
||||
},
|
||||
removeListener(event_name, cb) {
|
||||
return EventSystem.prototype.removeListener.call(this, event_name, cb);
|
||||
},
|
||||
//Events
|
||||
/*dispatchEvent(event_name, data) {
|
||||
let list = this.events[event_name];
|
||||
let results;
|
||||
if (list) {
|
||||
@ -296,27 +279,20 @@ const Blockbench = {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Validator.triggers.includes(event_name)) {
|
||||
Validator.validate(event_name);
|
||||
}
|
||||
return results;
|
||||
},
|
||||
addListener(event_names, cb) {
|
||||
event_names.split(' ').forEach(event_name => {
|
||||
if (!this.events[event_name]) {
|
||||
this.events[event_name] = [];
|
||||
}
|
||||
this.events[event_name].safePush(cb);
|
||||
})
|
||||
return Blockbench;
|
||||
},
|
||||
on(event_name, cb) {
|
||||
return Blockbench.addListener(event_name, cb)
|
||||
return EventSystem.prototype.on.call(this, event_name, cb);
|
||||
},
|
||||
once(event_name, cb) {
|
||||
return EventSystem.prototype.once.call(this, event_name, cb);
|
||||
},
|
||||
addListener(event_name, cb) {
|
||||
return EventSystem.prototype.addListener.call(this, event_name, cb);
|
||||
},
|
||||
removeListener(event_name, cb) {
|
||||
if (!this.events[event_name]) return;
|
||||
this.events[event_name].remove(cb);
|
||||
},*/
|
||||
return EventSystem.prototype.removeListener.call(this, event_name, cb);
|
||||
},
|
||||
// Update
|
||||
onUpdateTo(version, callback) {
|
||||
if (LastVersion && compareVersions(version, LastVersion) && !Blockbench.isOlderThan(version)) {
|
||||
|
@ -16,6 +16,7 @@ class ReferenceImage {
|
||||
this.source = '';
|
||||
|
||||
this.uuid = guid();
|
||||
this.cache_version = 0;
|
||||
this.condition = data.condition;
|
||||
|
||||
for (let key in ReferenceImage.properties) {
|
||||
@ -151,7 +152,7 @@ class ReferenceImage {
|
||||
ReferenceImageMode.saveGlobalReferences();
|
||||
break;
|
||||
case 'built_in':
|
||||
// todo: save
|
||||
// built in references are not saved
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
@ -195,7 +196,9 @@ class ReferenceImage {
|
||||
if (this.flip_y) transforms.push('scaleY(-1)');
|
||||
this.img.style.transform = transforms.join(' ');
|
||||
|
||||
if (this.img.src != this.source) this.img.src = this.source;
|
||||
if (this.img.src.split('?')[0] != this.source) {
|
||||
this.img.src = this.source + (this.cache_version ? ('?'+this.cache_version) : '');
|
||||
}
|
||||
|
||||
this.img.style.imageRendering = (this.img.naturalWidth > this.size[0]) ? 'auto' : 'pixelated';
|
||||
|
||||
@ -554,7 +557,9 @@ class ReferenceImage {
|
||||
position: {type: 'vector', label: 'reference_image.position', dimensions: 2, value: this.position},
|
||||
size: {type: 'vector', label: 'reference_image.size', dimensions: 2, value: this.size},
|
||||
rotation: {type: 'number', label: 'reference_image.rotation', value: this.rotation},
|
||||
opacity: {type: 'range', label: 'reference_image.opacity', editable_range_label: true, value: this.opacity, min: 0, max: 1}
|
||||
opacity: {type: 'range', label: 'reference_image.opacity', editable_range_label: true, value: this.opacity, min: 0, max: 1},
|
||||
visibility: {type: 'checkbox', label: 'reference_image.visibility', value: this.visibility},
|
||||
clear_mode: {type: 'checkbox', label: 'reference_image.clear_mode', value: this.clear_mode},
|
||||
},
|
||||
onConfirm: (result) => {
|
||||
let clear_mode_before = this.clear_mode;
|
||||
@ -571,17 +576,20 @@ class ReferenceImage {
|
||||
}
|
||||
}
|
||||
ReferenceImage.prototype.menu = new Menu([
|
||||
/**
|
||||
* Todo
|
||||
Visibility
|
||||
Restore
|
||||
Refresh file
|
||||
*/
|
||||
{
|
||||
id: 'visibility',
|
||||
name: 'reference_image.visibility',
|
||||
icon: (ref) => ref.visibility,
|
||||
click(ref) {
|
||||
ref.visibility = !ref.visibility;
|
||||
ref.update().save();
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'clear_mode',
|
||||
name: 'reference_image.clear_mode',
|
||||
icon: (ref) => ref.clear_mode,
|
||||
condition: ref => ref.layer == 'blueprint',
|
||||
//condition: ref => ref.layer == 'blueprint',
|
||||
click(ref) {
|
||||
ref.clear_mode = !ref.clear_mode;
|
||||
ref.updateClearMode();
|
||||
@ -622,6 +630,15 @@ ReferenceImage.prototype.menu = new Menu([
|
||||
}
|
||||
},
|
||||
'_',
|
||||
{
|
||||
name: 'menu.texture.refresh',
|
||||
icon: 'refresh',
|
||||
condition: (reference) => (isApp && PathModule.isAbsolute(reference.source)),
|
||||
click(reference) {
|
||||
reference.cache_version++;
|
||||
reference.update();
|
||||
}
|
||||
},
|
||||
'delete',
|
||||
'_',
|
||||
{
|
||||
@ -795,10 +812,28 @@ BARS.defineActions(function() {
|
||||
let list = [];
|
||||
function getSubMenu(reference) {
|
||||
return [
|
||||
{
|
||||
id: 'visibility',
|
||||
name: 'reference_image.visibility',
|
||||
icon: () => reference.visibility,
|
||||
click() {
|
||||
reference.visibility = !reference.visibility;
|
||||
reference.update().save();
|
||||
}
|
||||
},
|
||||
'_',
|
||||
{
|
||||
name: 'menu.texture.refresh',
|
||||
icon: 'refresh',
|
||||
condition: (reference) => (isApp && PathModule.isAbsolute(reference.source)),
|
||||
click(reference) {
|
||||
reference.cache_version++;
|
||||
reference.update();
|
||||
}
|
||||
},
|
||||
/** Todo: add options
|
||||
* Center
|
||||
* Delete
|
||||
* Visibility
|
||||
*/
|
||||
{
|
||||
name: 'Properties...',
|
||||
|
File diff suppressed because one or more lines are too long
@ -1828,6 +1828,7 @@
|
||||
"reference_image.size": "Size",
|
||||
"reference_image.rotation": "Rotation",
|
||||
"reference_image.opacity": "Opacity",
|
||||
"reference_image.visibility": "Visibility",
|
||||
"reference_image.clear_mode": "Clear Mode",
|
||||
"reference_image.layer": "Layer",
|
||||
"reference_image.layer.background": "Behind Model",
|
||||
|
Loading…
Reference in New Issue
Block a user