A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

99 linhas
3.0KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import Utils from "/app/js/common/Utils.js";
  3. import Input from "/app/js/ui/Input.js";
  4. class Modal{
  5. constructor(){
  6. this.__currentModalEl = null;
  7. window.addEventListener("click", (function(event){
  8. if (event.target === this.__currentModalEl){
  9. this.close_modal();
  10. }
  11. }).bind(this));
  12. GlobalEvents.listen("modal-open", (function(target, event){
  13. var force = (event.hasOwnProperty("force")) ? event.force === true : false;
  14. if (event.hasOwnProperty("id") && typeof(event.id) === 'string'){
  15. this.open_modal_id(event.id, force);
  16. } else if (event.hasOwnProperty("cls") && typeof(event.cls) === 'string'){
  17. this.open_modal_class(event.cls, force);
  18. }
  19. }).bind(this));
  20. GlobalEvents.listen("modal-close", (function(target, event){
  21. this.close_modal();
  22. }).bind(this));
  23. // TODO: Deprecate this mechanic. Let other controllers directly handle input.
  24. GlobalEvents.listen("modal-submit", (function(target, event){
  25. if (!event.hasOwnProperty("subevent"))
  26. return;
  27. var ename = event.subevent;
  28. var vals = {};
  29. if (event.hasOwnProperty("ids")){
  30. var ids = event.ids.split(",");
  31. var cel = this.__currentModalEl;
  32. ids.forEach((item) => {
  33. var id = item.trim();
  34. var el = cel.querySelector("[name='" + id + "']");
  35. if (el) // TODO: Check if el is an INPUT node and switch between the node types.
  36. vals[id] = el.value;
  37. });
  38. }
  39. GlobalEvents.emit(ename, vals);
  40. if (event.hasOwnProperty("closeoncomplete"))
  41. this.close_modal();
  42. }).bind(this));
  43. }
  44. get currentModalElement(){
  45. return this.__currentModalEl;
  46. }
  47. open_modal_id(idname, force=false){
  48. var el = document.getElementById(idname);
  49. /*if (el.classList.contains("modal") && this.__currentModalEl !== el){
  50. if (this.__currentModalEl !== null && force)
  51. this.close_modal();
  52. if (this.__currentModalEl === null){
  53. if (el){
  54. return this.open_modal_element(el);
  55. }
  56. }
  57. }*/
  58. return (el) ? this.open_modal_element(el, force) : this;
  59. }
  60. open_modal_class(clsname, force=false){
  61. var el = document.querySelector((clsname.indexOf(".") < 0) ? "." + clsname : clsname);
  62. return (el) ? this.open_modal_element(el, force) : this;
  63. }
  64. open_modal_element(el, force=false){
  65. if (Utils.isElement(el)){
  66. if (el.classList.contains("modal") && this.__currentModalEl !== el){
  67. if (this.__currentModalEl !== null && force)
  68. this.close_modal();
  69. if (this.__currentModalEl === null){
  70. el.classList.add("modal-visible");
  71. this.__currentModalEl = el;
  72. }
  73. }
  74. }
  75. return this;
  76. }
  77. close_modal(){
  78. if (this.__currentModalEl !== null){
  79. this.__currentModalEl.classList.remove("modal-visible");
  80. this.__currentModalEl = null;
  81. }
  82. return this;
  83. }
  84. }
  85. const instance = new Modal();
  86. export default instance;