Browse Source

Updated CTRLPalettesStore and CTRLBanksStore (and associative *ListItem.html files to use the new EditableText class.

dev
Bryan Miller 5 years ago
parent
commit
d706e08883
4 changed files with 33 additions and 29 deletions
  1. +13
    -13
      app/js/ctrls/CTRLBanksStore.js
  2. +18
    -16
      app/js/ctrls/CTRLPalettesStore.js
  3. +1
    -0
      views/bankListItem.html
  4. +1
    -0
      views/paletteListItem.html

+ 13
- 13
app/js/ctrls/CTRLBanksStore.js View File

import GlobalEvents from "/app/js/common/EventCaller.js"; import GlobalEvents from "/app/js/common/EventCaller.js";
import Utils from "/app/js/common/Utils.js"; import Utils from "/app/js/common/Utils.js";
import EditableText from "/app/js/ui/EditableText.js";
import Renderer from "/app/js/ui/Renderer.js"; import Renderer from "/app/js/ui/Renderer.js";
import NESBank from "/app/js/models/NESBank.js"; import NESBank from "/app/js/models/NESBank.js";
import NESPalette from "/app/js/models/NESPalette.js"; import NESPalette from "/app/js/models/NESPalette.js";




function SetElBankName(el, name){ function SetElBankName(el, name){
el.setAttribute("bankname", name);
var sel = el.querySelector("." + BLI_TITLE);
if (sel){
sel.innerHTML = name;
}
var et = new EditableText(el, "title");
et.listen("value_change", (v) => {el.setAttribute("bankname", v);});
et.value = name;
return et;
//var sel = el.querySelector("." + BLI_TITLE);
//if (sel){
// sel.innerHTML = name;
//}
} }




el.classList.remove(BLI_TEMPLATE); el.classList.remove(BLI_TEMPLATE);
el.classList.remove("hidden"); el.classList.remove("hidden");
el.setAttribute("bankname", name); el.setAttribute("bankname", name);
ConnectElementToBank(el, bank);
SetElBankName(el, name);
ConnectElementToBank(el, bank);
el.addEventListener("click", HANDLE_BankClick); el.addEventListener("click", HANDLE_BankClick);
baseel.parentNode.appendChild(el); baseel.parentNode.appendChild(el);
setTimeout(()=>{ setTimeout(()=>{
if (bank !== null){ if (bank !== null){
var el = CreateBankDOMEntry(name, bank); var el = CreateBankDOMEntry(name, bank);
if (el){ if (el){
Banks[name] = {bank:bank, el:el};
//Banks.push([name, bank, el]);
var elname = SetElBankName(el, name);
Banks[name] = {bank:bank, el:el, elname:elname};


if (this.length <= 1){ if (this.length <= 1){
Banks[name].el.click(); Banks[name].el.click();
//GlobalEvents.emit("change_surface", bank);
} }
} }
} }
renameBank(name, newname){ renameBank(name, newname){
if ((name in Banks) && !(newname in Banks)){ if ((name in Banks) && !(newname in Banks)){
Banks[newname] = Banks[name]; Banks[newname] = Banks[name];
Banks[newname].elname.value = newname;
delete Banks[name]; delete Banks[name];
SetElBankName(Banks[newname].el, newname);
} }
return this; return this;
} }
activateBank(name){ activateBank(name){
if (CurrentBank !== name && (name in Banks)){ if (CurrentBank !== name && (name in Banks)){
Banks[name].el.click(); Banks[name].el.click();
//CurrentBank = name;
//GlobalEvents.emit("change_surface", Banks[CurrentBank].bank);
} }
return this; return this;
} }

+ 18
- 16
app/js/ctrls/CTRLPalettesStore.js View File

import GlobalEvents from "/app/js/common/EventCaller.js"; import GlobalEvents from "/app/js/common/EventCaller.js";
import Utils from "/app/js/common/Utils.js"; import Utils from "/app/js/common/Utils.js";
import EditableText from "/app/js/ui/EditableText.js";
import NESPalette from "/app/js/models/NESPalette.js"; import NESPalette from "/app/js/models/NESPalette.js";




var pname = this.getAttribute("palname"); var pname = this.getAttribute("palname");


if (Palettes.length > 0){ if (Palettes.length > 0){
if (Palettes[CurrentPaletteIndex][0] !== pname || !Palettes[CurrentPaletteIndex][2].classList.contains(PLI_SELECTED)){
if (Palettes[CurrentPaletteIndex][0].value !== pname || !Palettes[CurrentPaletteIndex][2].classList.contains(PLI_SELECTED)){
var oel = Palettes[CurrentPaletteIndex][2]; var oel = Palettes[CurrentPaletteIndex][2];
oel.classList.remove(PLI_SELECTED); oel.classList.remove(PLI_SELECTED);


for (let i=0; i < Palettes.length; i++){ for (let i=0; i < Palettes.length; i++){
if (Palettes[i][0] === pname){
if (Palettes[i][0].value === pname){
Palettes[i][2].classList.add(PLI_SELECTED); Palettes[i][2].classList.add(PLI_SELECTED);
CurrentPaletteIndex = i; CurrentPaletteIndex = i;
GlobalEvents.emit("set_app_palette", Palettes[i][1]); GlobalEvents.emit("set_app_palette", Palettes[i][1]);


function SetElPaletteName(el, pname){ function SetElPaletteName(el, pname){
el.setAttribute("palname", pname); el.setAttribute("palname", pname);
var sel = el.querySelectorAll("." + PLI_TITLE);
var et = new EditableText(el, "title");
et.value = pname;
et.listen("value_change", (v) => {el.setAttribute("palname", v);});
return et;
/*var sel = el.querySelectorAll("." + PLI_TITLE);
if (sel.length === 1){ if (sel.length === 1){
sel = sel[0]; sel = sel[0];
sel.innerHTML = pname; sel.innerHTML = pname;
}
}*/
} }


function SetElToColor(el, mode, pi, ci, hex){ function SetElToColor(el, mode, pi, ci, hex){
el.classList.remove("hidden"); el.classList.remove("hidden");
ConnectElementToPalette(el, palette); ConnectElementToPalette(el, palette);
ColorElementToPalette(el, palette); ColorElementToPalette(el, palette);
SetElPaletteName(el, pname);
//SetElPaletteName(el, pname);
el.addEventListener("click", HANDLE_PaletteClick); el.addEventListener("click", HANDLE_PaletteClick);
oel[0].parentNode.appendChild(el); oel[0].parentNode.appendChild(el);
return el; return el;


paletteIndexFromName(name){ paletteIndexFromName(name){
for (let i=1; i < Palettes.length; i++){ for (let i=1; i < Palettes.length; i++){
if (Palettes[i][0] == name){
if (Palettes[i][0].value == name){
return i; return i;
} }
} }


if (palette !== null){ if (palette !== null){
var el = CreatePaletteDOMEntry(name, palette); var el = CreatePaletteDOMEntry(name, palette);
Palettes.push([name, palette, el]);
var eltitle = SetElPaletteName(el, name);
Palettes.push([eltitle, palette, el]);


if (Palettes.length <= 1 && !BlockEmits){ if (Palettes.length <= 1 && !BlockEmits){
//GlobalEvents.emit("set_app_palette", palette);
el.click(); el.click();
} }
} }


removePalette(name){ removePalette(name){
for (let i=0; i < Palettes.length; i++){ for (let i=0; i < Palettes.length; i++){
if (Palettes[i][0] === name){
if (Palettes[i][0].value === name){
if (CurrentPaletteIndex === i){ if (CurrentPaletteIndex === i){
CurrentPaletteIndex = 0; CurrentPaletteIndex = 0;
this.activatePalette(Palettes[0][0]);
this.activatePalette(Palettes[0][0].value);
} }
Palettes[i][2].parentNode.removeChild(Palettes[i][2]); Palettes[i][2].parentNode.removeChild(Palettes[i][2]);
Palettes.splice(i, 1); Palettes.splice(i, 1);
} }


renamePalette(oldname, newname){ renamePalette(oldname, newname){
var i = paletteIndexFromName(oldname);
var i = this.paletteIndexFromName(oldname);
if (i < 0) if (i < 0)
throw new ValueError("Failed to find palette named '" + oldname +"'. Cannot rename."); throw new ValueError("Failed to find palette named '" + oldname +"'. Cannot rename.");
Palettes[i][0] = newname;
SetElPaletteName(Palettes[i][2], newname);
Palettes[i][0].value = newname;
//SetElPaletteName(Palettes[i][2], newname);
return this; return this;
} }


var i = this.paletteIndexFromName(name); var i = this.paletteIndexFromName(name);
if (i >= 0 && CurrentPaletteIndex !== i){ if (i >= 0 && CurrentPaletteIndex !== i){
Palettes[CurrentPaletteIndex][2].click(); Palettes[CurrentPaletteIndex][2].click();
//if (!BlockEmits){
// GlobalEvents.emit("set_app_palette", Palettes[CurrentPaletteIndex][1]);
//}
} }
return this; return this;
} }

+ 1
- 0
views/bankListItem.html View File

<div class="list-h-padding list-v-padding" style="display:flex"> <div class="list-h-padding list-v-padding" style="display:flex">
<canvas class="bank-img" width="152" height="74"></canvas> <canvas class="bank-img" width="152" height="74"></canvas>
<span class="title">Title here</span> <span class="title">Title here</span>
<input class="title hidden" type="text" value="Title here"></input>
</div> </div>
</div> </div>

+ 1
- 0
views/paletteListItem.html View File

<div class=pure-g"> <div class=pure-g">
<div class=pure-u-1"> <div class=pure-u-1">
<span class="title">Title here</span> <span class="title">Title here</span>
<input class="title hidden" type="text" value="Title here"></input>
</div> </div>
</div> </div>
<div class="pure-g"> <div class="pure-g">

Loading…
Cancel
Save