Ezelia / EZGUI

EZGUI - The missing GUI for Pixi.js and Phaser.io
http://ezgui.ezelia.com
440 stars 95 forks source link

closing windows and opening a new one #31

Closed scabros closed 8 years ago

scabros commented 8 years ago

hi, i cant figure exactly which is the correct procedure to close a window clicking on a button inside that window and at the same time, open another window, with a different id of course. right now i am trying this (TplObj is the window template object):

TplObj.id = 'enc_' + turn;
TplObj.children[0].text = 'You have found something!';
guiContainer = EZGUI.create(TplObj, 'kenney');
EZGUI.components.btnclose.on('click', function (event) {
  closeEncounter(E, 'close');
});

and my closeEncounter:

guiContainer.destroy();
delete guiContainer;
ActObj.id = 'act_' + turn;
ActObj.children[0].text = 'You tried to ' + action + ' with \n' + E.desc + '!';
actionContainer = EZGUI.create(ActObj, 'kenney');
EZGUI.components.btncloseaction.on('click', function (event) {
  closeAction();
});

this, in some way, does dissapear the window. but it doesnt "unbind" the click from the btnclose region. how should i do this?

thanks in advance.

scabros commented 8 years ago

just to clarify, to close the new opened window, i must drag it to another region of the canvas where there has not been another windows previously...

scabros commented 8 years ago

ok, i found a "workaround" (or maybe is just the correct way of doing this):

i must call .destroy() method for every component of the window.

so, if i have a window with one header title, one layout, one label and another layout with four buttons i do:

EZGUI.components.btnone.destroy(); // button
EZGUI.components.btntwo.destroy(); // button
EZGUI.components.btnthree.destroy(); // button
EZGUI.components.btnfour.destroy(); // button
EZGUI.components.ttl.destroy(); // header title 
EZGUI.components.encdesc.destroy(); // description label
EZGUI.components.btnsLay.destroy(); // layout containing buttons

hope this helps someone with the same problem!

@alaa-eddine , maybe this could be added to the documentation wiki?