Merge branch 'feature-color-palette'

This commit is contained in:
jdescottes 2014-04-09 23:39:20 +02:00
commit d42064d2fe
10 changed files with 67 additions and 24 deletions

View File

@ -123,15 +123,10 @@
font-weight: bold;
}
.palette-manager-details-head-edit-icon {
cursor: pointer;
.palette-manager-details-head .edit-icon {
width: 24px;
height: 100%;
background: url('../img/tools/pen.png');
display: inline-block;
background-size: 20px;
background-repeat: no-repeat;
background-position: 50%;
background-size: 16px;
}
.palette-manager-details-head-actions {

10
src/css/icons.css Normal file
View File

@ -0,0 +1,10 @@
.action-icon {
cursor: pointer;
height: 100%;
background-repeat: no-repeat;
background-position: 50%;
}
.action-icon.edit-icon {
background-image: url('../img/tools/pen.png');
}

View File

@ -19,11 +19,27 @@
.layer-item {
height:24px;
line-height: 24px;
padding : 0 10px;
padding : 0 0 0 10px;
border-top: 1px solid #444;
cursor : pointer;
}
.layer-item .edit-icon {
float: right;
width: 30px;
background-size: 12px;
opacity: 0;
transition : opacity 0.2s;
}
.layer-item:hover .edit-icon {
opacity : 0.6;
}
.layer-item:hover .edit-icon:hover {
opacity : 1;
}
.layer-item:hover {
background : #222;
}

View File

@ -23,24 +23,37 @@
layers.forEach(this.addLayerItem.bind(this));
};
ns.LayersListController.prototype.addLayerItem = function (layer) {
ns.LayersListController.prototype.addLayerItem = function (layer, index) {
var isSelected = this.piskelController.getCurrentLayer() === layer;
var layerItemHtml = pskl.utils.Template.replace(this.layerItemTemplate_, {
layername : layer.getName()
'layername' : layer.getName(),
'layerindex' : index,
'isselected:current-layer-item' : isSelected
});
var layerItem = pskl.utils.Template.createFromHTML(layerItemHtml);
if (this.piskelController.getCurrentLayer() === layer) {
layerItem.classList.add('current-layer-item');
}
this.layersListEl.insertBefore(layerItem, this.layersListEl.firstChild);
};
ns.LayersListController.prototype.onClick_ = function (evt) {
var el = evt.target || evt.srcElement;
if (el.nodeName == 'BUTTON') {
var index;
if (el.classList.contains('button')) {
this.onButtonClick_(el);
} else if (el.nodeName == 'LI') {
var layerName = el.getAttribute('data-layer-name');
this.piskelController.selectLayerByName(layerName);
} else if (el.classList.contains('layer-item')) {
index = el.dataset.layerIndex;
this.piskelController.setCurrentLayerIndex(parseInt(index, 10));
} else if (el.classList.contains('edit-icon')) {
index = el.parentNode.dataset.layerIndex;
var layer = this.piskelController.getLayerByIndex(parseInt(index, 10));
this.renameLayer_(layer);
}
};
ns.LayersListController.prototype.renameLayer_ = function (layer) {
var newName = window.prompt("Please enter the layer name", layer.getName());
if (newName) {
layer.setName(newName);
this.renderLayerList_();
}
};

View File

@ -161,10 +161,12 @@
}
};
ns.PiskelController.prototype.selectLayerByName = function (name) {
if (this.hasLayerForName_(name)) {
var layer = this.piskel.getLayersByName(name)[0];
this.selectLayer(layer);
ns.PiskelController.prototype.getLayerByIndex = function (index) {
var layers = this.getLayers();
if (layers[index]) {
return layers[index];
} else {
return null;
}
};

View File

@ -6,7 +6,7 @@
var SELECTED_CLASSNAME = 'selected';
var NEW_COLOR_CLASS = 'palette-manager-new-color';
var CLOSE_ICON_CLASS = 'palette-manager-delete-card';
var EDIT_NAME_CLASS = 'palette-manager-details-head-edit-icon';
var EDIT_NAME_CLASS = 'edit-icon';
ns.PaletteManagerController = function (piskelController) {
this.piskelController = piskelController;

View File

@ -27,6 +27,10 @@
return this.name;
};
ns.Layer.prototype.setName = function (name) {
this.name = name;
};
ns.Layer.prototype.getFrames = function () {
return this.frames;
};

View File

@ -6,6 +6,7 @@ exports.styles = [
"css/forms.css",
"css/settings.css",
"css/tools.css",
"css/icons.css",
"css/cheatsheet.css",
"css/dialogs.css",
"css/dialogs-manage-palettes.css",

View File

@ -21,7 +21,7 @@
<script type="text/template" id="palette-details-head-template">
<span class="palette-manager-details-head-name">{{name}}</span>
<span class="palette-manager-details-head-edit-icon" title="edit name">&nbsp;</span>
<span class="action-icon edit-icon" title="edit name">&nbsp;</span>
<div class="palette-manager-details-head-actions">
<button class="palette-manager-palette-button button button-primary" {{save:disabled}} data-action="save" type="button">Save</button>
<button class="palette-manager-palette-button button " {{revert:disabled}} data-action="revert" type="button">Revert</button>

View File

@ -7,7 +7,9 @@
<button class="button toolbox-button layers-button-arrow" data-action="down" >&#8595;</button>
</div>
<script type="text/template" id="layer-item-template">
<li class="layer-item" data-layer-name="{{layername}}">{{layername}}</li>
<li class="layer-item {{isselected:current-layer-item}}" data-layer-index="{{layerindex}}">{{layername}}
<span class="action-icon edit-icon" title="edit name">&nbsp;</span>
</li>
</script>
<ul class="layers-list"></ul>
</div>