Sfoglia il codice sorgente

Enhancements to the Nametable Tools and associated UI.

dev
Bryan Miller 5 anni fa
parent
commit
e4f01f7143
3 ha cambiato i file con 43 aggiunte e 9 eliminazioni
  1. +38
    -8
      app/js/ctrls/CTRLNametableTools.js
  2. +4
    -0
      sass/core.scss
  3. +1
    -1
      views/toolbar_nametable.html

+ 38
- 8
app/js/ctrls/CTRLNametableTools.js Vedi File

import NESNameTable from "/app/js/models/NESNameTable.js"; import NESNameTable from "/app/js/models/NESNameTable.js";
import CTRLBanksStore from "/app/js/ctrls/CTRLBanksStore.js"; import CTRLBanksStore from "/app/js/ctrls/CTRLBanksStore.js";


const TILE_SELECT_CLS = "canvas-item-selected";

var ELCtrl = null; var ELCtrl = null;
var SURF = null; var SURF = null;
var TileIndex = -1; var TileIndex = -1;
} else { } else {
var elsel = ELCtrl.querySelector(".nametable-tile-select"); var elsel = ELCtrl.querySelector(".nametable-tile-select");
if (elsel){ if (elsel){
el.classList.remove("hidden");
let tiles = SURF.bank.rp; let tiles = SURF.bank.rp;
for (let i=0; i < tiles.length; i++){ for (let i=0; i < tiles.length; i++){
let cnv = elsel.querySelector('canvas[value="' + i + '"]');
let cnv = elsel.querySelector('canvas[value="' + i + '"]');
if (cnv){ if (cnv){
var psize = Math.floor(cnv.parentNode.clientWidth * 0.9);
if (cnv.clientWidth !== psize){
cnv.width = psize;
cnv.height = psize;
}
let ctx = cnv.getContext("2d"); let ctx = cnv.getContext("2d");
let tsurf = new Renderer.NESTileSurface(tiles[i], SURF.palette, 0); let tsurf = new Renderer.NESTileSurface(tiles[i], SURF.palette, 0);
Renderer.renderToFit(tsurf, ctx); Renderer.renderToFit(tsurf, ctx);
} }
}
el.classList.remove("hidden");
}
} }
} }
} }
SURF.bank = null; SURF.bank = null;
curbankname = "NULL_BANK"; curbankname = "NULL_BANK";
} }
UpdateBankList(curbankname);
UpdateBankTileList();
ELCtrl.classList.remove("hidden"); ELCtrl.classList.remove("hidden");
UpdateBankList(curbankname);
UpdateBankTileList();
} }
} }


} }
} }


function ResetSelectedTile(){
var eltilesel = ELCtrl.querySelector(".nametable-tile-select");
if (eltilesel){
var op = eltilesel.querySelector('canvas[selected="True"]');
if (op){
op.classList.remove(TILE_SELECT_CLS);
op.removeAttribute("selected");
}
}
TileIndex = -1;
}

function HANDLE_SurfChange(surf){ function HANDLE_SurfChange(surf){
if (surf instanceof NESNameTable){ if (surf instanceof NESNameTable){
if (SURF !== null) if (SURF !== null)
SURF.unlisten("paint_nametable", HANDLE_PaintNametable); SURF.unlisten("paint_nametable", HANDLE_PaintNametable);
SURF = surf; SURF = surf;
SURF.listen("paint_nametable", HANDLE_PaintNametable); SURF.listen("paint_nametable", HANDLE_PaintNametable);
ResetSelectedTile();
OpenControls(); OpenControls();
} else { } else {
if (SURF !== null) if (SURF !== null)
if (!eltilesel) if (!eltilesel)
throw new Error("Failed to find element class 'nametable-tile-select' within toolbar."); throw new Error("Failed to find element class 'nametable-tile-select' within toolbar.");



var HANDLE_TileSelect = function(){
var oop = eltilesel.querySelector('canvas[selected="True"]');
if (oop){
oop.classList.remove(TILE_SELECT_CLS);
oop.removeAttribute("selected");
}
this.setAttribute("selected", "True");
this.classList.add(TILE_SELECT_CLS);
TileIndex = parseInt(this.getAttribute("value"));
};
var op0 = eltilesel.querySelector('canvas[value="0"]'); var op0 = eltilesel.querySelector('canvas[value="0"]');
if (!op0) if (!op0)
throw new Error("Failed to find initial canvas element within 'nametable-tile-select'."); throw new Error("Failed to find initial canvas element within 'nametable-tile-select'.");


op0.addEventListener("click", HANDLE_TileSelect);
for (let i=1; i < 256; i++){ for (let i=1; i < 256; i++){
let op = eltilesel.querySelector('canvas[value="' + i + '"]'); let op = eltilesel.querySelector('canvas[value="' + i + '"]');
if (!op){ if (!op){
op = op0.cloneNode(true); op = op0.cloneNode(true);
op.setAttribute("value", i); op.setAttribute("value", i);
eltilesel.appendChild(op); eltilesel.appendChild(op);
op.addEventListener("click", function(){
TileIndex = parseInt(this.getAttribute("value"));
});
op.addEventListener("click", HANDLE_TileSelect);
} }
} }



+ 4
- 0
sass/core.scss Vedi File

display: flex; display: flex;
} }


canvas.canvas-item-selected{
border: 3px solid #FF0000;
}

// Used to hide the ENTIRE page until the system has finished readying // Used to hide the ENTIRE page until the system has finished readying
// everything. // everything.
.cover { .cover {

+ 1
- 1
views/toolbar_nametable.html Vedi File

<div class="pure-control-group simple-padding-top nametable-tile hidden"> <div class="pure-control-group simple-padding-top nametable-tile hidden">
Bank Tile: Bank Tile:
<div class="list-container nametable-tile-select"> <div class="list-container nametable-tile-select">
<canvas width="8" height="8" value="0"></canvas>
<canvas width="8" height="8" value="0"></canvas>
</div> </div>
</div> </div>
</form> </form>

Loading…
Annulla
Salva