Просмотр исходного кода

Updated drawing palette UI.

dev
Bryan Miller 6 лет назад
Родитель
Сommit
20aab57e83
3 измененных файлов: 64 добавлений и 67 удалений
  1. +14
    -39
      app/js/ctrls/CTRLPalettes.js
  2. +20
    -0
      sass/nespalette.scss
  3. +30
    -28
      views/paldraw.html

+ 14
- 39
app/js/ctrls/CTRLPalettes.js Просмотреть файл

const ATTRIB_PALIDX = "pidx"; // This is the palette index (0 - 3 (Tiles) 4 - 7 (Sprites)) const ATTRIB_PALIDX = "pidx"; // This is the palette index (0 - 3 (Tiles) 4 - 7 (Sprites))
const ATTRIB_COLIDX = "cidx"; // This is the color index in the selected palette (0 - 3) const ATTRIB_COLIDX = "cidx"; // This is the color index in the selected palette (0 - 3)


const CLASS_BTN_ACTIVE = "pure-button-active";
const SELECT_ID_PALETTEMODE = "palette-mode";
const CLASS_PALETTE_ACTIVE = "palette-selected";


var Active_Palette_Index = 0; var Active_Palette_Index = 0;
var Active_Color_Index = 0; var Active_Color_Index = 0;
ci = parseInt(ci); ci = parseInt(ci);
else else
ci = -1; ci = -1;
if (pi >= 0 && pi < 4 && ci >= 0 && ci < 4){
if (pi >= 0 && pi < 8 && ci >= 0 && ci < 4){
return {pi:pi, ci:ci}; return {pi:pi, ci:ci};
} }
} }
el.style.color = InvertColor(c); el.style.color = InvertColor(c);
} }


function SetColorPaletteEls(mode, pal){
function SetColorPaletteEls(pal){
var elist = document.querySelectorAll("[" + ATTRIB_PALIDX + "]"); var elist = document.querySelectorAll("[" + ATTRIB_PALIDX + "]");
elist.forEach(function(el){ elist.forEach(function(el){
var i = GetPaletteIndexes(el); var i = GetPaletteIndexes(el);
if (i !== null){ if (i !== null){
SetPaletteElStyle(el, pal.get_palette_color((mode*4) + i.pi, i.ci));
SetPaletteElStyle(el, pal.get_palette_color(i.pi, i.ci));
} }
}); });
} }


function FindAndColorPalette(mode, pi, ci, pal){
if ((mode == 0 && pi < 4) || (mode == 1 && pi >= 4)){
var el = document.querySelector("[" + ATTRIB_PALIDX +"='" + (pi%4) + "']" +
function FindAndColorPalette(pi, ci, pal){
if (pi >= 0 && pi < 8){
var el = document.querySelector("[" + ATTRIB_PALIDX +"='" + pi + "']" +
"[" + ATTRIB_COLIDX + "='" + ci + "']"); "[" + ATTRIB_COLIDX + "='" + ci + "']");
if (el){ if (el){
SetPaletteElStyle(el, pal.get_palette_color(pi, ci)); SetPaletteElStyle(el, pal.get_palette_color(pi, ci));
constructor(){ constructor(){
this.__NESPalette = null; this.__NESPalette = null;
this.__activePaletteEl = null; this.__activePaletteEl = null;
this.__mode = 0; // 0 = Tile palette mode | 1 = Sprite palette mode.


var self = this; var self = this;


var i = GetPaletteIndexes(this); var i = GetPaletteIndexes(this);
if (i !== null){ if (i !== null){
if (self.__activePaletteEl !== null){ if (self.__activePaletteEl !== null){
self.__activePaletteEl.classList.remove(CLASS_BTN_ACTIVE);
self.__activePaletteEl.classList.remove(CLASS_PALETTE_ACTIVE);
} }
this.classList.add(CLASS_BTN_ACTIVE);

this.classList.add(CLASS_PALETTE_ACTIVE);
self.__activePaletteEl = this; self.__activePaletteEl = this;
GlobalEvents.emit("active_palette_color", i.pi, i.ci);
GlobalEvents.emit("active_palette_color", (i.pi%4), i.ci);
} }
} }
} }




// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
// Defining hooks for palette mode swapping
// ------------------------------------------------------------------------------------
var el = document.querySelector("#" + SELECT_ID_PALETTEMODE);
if (el){
el.addEventListener("change", function(event){
switch(this.value){
case "sprite":
self.__mode = 1; break;
case "tile":
self.__mode = 0; break;
}
SetColorPaletteEls(self.__mode, self.__NESPalette);
});
}

// ------------------------------------------------------------------------------------
// Setting some hooks to watch for some global events. // Setting some hooks to watch for some global events.
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
var handle_set_app_palette = function(p){ var handle_set_app_palette = function(p){
} }
} }
GlobalEvents.listen("set_app_palette", handle_set_app_palette); GlobalEvents.listen("set_app_palette", handle_set_app_palette);

var handle_palettemode = (function(mode){
if (mode === 0 || mode ===1){
this.__mode = mode;
SetColorPaletteEls(this.__mode, this.__NESPalette);
}
}).bind(this);
GlobalEvents.listen("set_palette_mode", handle_palettemode);
} }


get palette(){ get palette(){
var handle_palettes_changed = function(event){ var handle_palettes_changed = function(event){
if (self.__NESPalette !== null){ if (self.__NESPalette !== null){
if (event.type == "ALL"){ if (event.type == "ALL"){
SetColorPaletteEls(self.__mode, self.__NESPalette);
SetColorPaletteEls(self.__NESPalette);
} else { } else {
FindAndColorPalette(self.__mode, event.pindex, event.cindex, self.__NESPalette);
FindAndColorPalette(event.pindex, event.cindex, self.__NESPalette);
} }
} }
} }
if (el.hasAttribute(ATTRIB_COLIDX)){ if (el.hasAttribute(ATTRIB_COLIDX)){
var i = GetPaletteIndexes(el); var i = GetPaletteIndexes(el);
if (i !== null){ if (i !== null){
SetPaletteElStyle(el, p.get_palette_color((this.__mode * 4) + i.pi, i.ci));
SetPaletteElStyle(el, p.get_palette_color(i.pi, i.ci));
} }
} }
}).bind(this)); }).bind(this));

+ 20
- 0
sass/nespalette.scss Просмотреть файл

.NES-palette button{ .NES-palette button{
width:2rem; width:2rem;
} }


.palette-unit-t, .palette-unit-full{
&.palette-selected{
box-shadow: inset 0px 3px $color-highlight;
}
}

.palette-unit-s, .palette-unit-full{
&.palette-selected{
box-shadow: inset 0px -3px $color-highlight;
}
}

.palette-unit-full{
&.palette-selected{
box-shadow: inset 3px 3px $color-highlight, inset 0px -3px $color-highlight;
}
}


+ 30
- 28
views/paldraw.html Просмотреть файл

<div class="pure-u-1-2">
<div class-"simple-padding">
<label for="palette-mode">
Drawing Palettes
</label>
<select id="palette-mode">
<option value="sprite">Sprite Palettes</option>
<option value="tile" selected>Tile Palettes</option>
</select>
</div>
<div class="pure-g">
<% for(var i=0; i < numpalettes; i++){ %>
<div class="pure-u-1-2">
<div class="simple-padding">
Palette <%= i+1 %>
</div>
<div class="simple-padding">
<div class="pure-button-group" role="group">
<button class="pure-button" cidx="0" pidx="<%= i %>">0</button>
<button class="pure-button" cidx="1" pidx="<%= i %>">1</button>
<button class="pure-button" cidx="2" pidx="<%= i %>">2</button>
<button class="pure-button" cidx="3" pidx="<%= i %>">3</button>
</div>
</div>
</div>
<% } %>
</div>
</div>
<div class="pure-u-1-2">
<div class="pure-g">
<% for(var i=0; i < numpalettes; i++){ %>
<div class="pure-u-1-2">
<div class="simple-padding">
Palette <%= i+1 %>
</div>
<div class="simple-padding">
<div class="pure-g pure-g-nw">
<div class="pure-u-1-4 palette-unit">
<div class="palette-unit-full" cidx="0" pidx="<%= i %>">&nbsp;<BR>&nbsp;</div>
</div>
<div class="pure-u-1-4 palette-unit">
<div class="palette-unit-t" cidx="1" pidx="<%= i %>">&nbsp;</div>
<div class="palette-unit-s" cidx="1" pidx="<%= (i+4) %>">&nbsp;</div>
</div>
<div class="pure-u-1-4 palette-unit">
<div class="palette-unit-t" cidx="2" pidx="<%= i %>">&nbsp;</div>
<div class="palette-unit-s" cidx="2" pidx="<%= (i+4) %>">&nbsp;</div>
</div>
<div class="pure-u-1-4 palette-unit">
<div class="palette-unit-t" cidx="3" pidx="<%= i %>">&nbsp;</div>
<div class="palette-unit-s" cidx="3" pidx="<%= (i+4) %>">&nbsp;</div>
</div>
</div>
</div>
</div>
<% } %>
</div>
</div>

Загрузка…
Отмена
Сохранить