Reactivate dragable

every day, a new question it seems :slight_smile:



i made a dragable window with scrollpanels and buttons in it, so far, so good.

its made to hide on close, but how can i get it back?

i have a button, thats always visible, which should bring on the window again and again, when needed.

how can that be done?

i tried the hide and show version, cause that worked for other stuff, but not for the dragable window when there is a scrollpanel in it, so that wont work here.

no one?

i just need to reactivate the window, once its closed :frowning:

this is what happens when you close the window and when you have hideOnClose set to true:



[java] @Override

public void closeWindow() {

if (hideOnClose) {

getElement().hide();

} else {

getElement().markForRemoval();

}

}

[/java]



the element gets hidden. that’s all. there is no black magic involved.



every element you hide() you should be able to show() again. what exactly does not “work” when you show the window after closing it?

well, the element is not visible from the start and once i click the button, that makes it show up, it works.

when i close it then, the button wont let it show up again. so it does what it should, but only once.



button:

[xml]<control id="help_button" name="button" label="?" width="25px" align="center" valign="center">

<interact onClick="show_help()"/>

</control>[/xml]



dragable window:

[xml]<layer id="help_window" childLayout="absolute" visible="false">

<control id="window1" name="window" title="help" hideOnClose="true" width="200px" height="200px" >

<text text="i dont work" style="base-font" color="#eeef" valign="center" width="100%" />

</control>

</layer>

[/xml]



method in controller:

[java]public void show_help(){

Element niftyElement = nifty.getCurrentScreen().findElementByName("help_window");

niftyElement.show();

}[/java]



makes no difference if i choose interact with manual java stuff, or the onclick effect way.

it works once, but never again.

:slight_smile:



you show the layer and not the window!



probably better:



[java]Element niftyElement = nifty.getCurrentScreen().findElementByName(“window1”);[/java]



and you should be able to always show that layer:



[xml]<layer id=“help_window” childLayout=“absolute” visible=“true”> // true not false[/xml]



which should make things easier.



I’ve just tried showing/hiding the same window here and it works pretty well! :slight_smile:

Hey void,



Just a little question about that.



Shouldn’t show() also show the children of the element it’s called on? What if there many children?



Trying to understand why it works that way. :slight_smile:

@madjack for me it shows… i use this code in my in controller:



-> public void showIngameMenu()

Element bgm = screen.findElementByName(“background-menu”);

if(bgm.isVisible())

{

bgm.hide();

game.getGameState().setState(GameStates.ActiveGame);

}

else

{

bgm.show();

game.getGameState().setState(GameStates.InactiveGame);

}

XML:

<layer id=“background-menu” childLayout=“center” backgroundColor="#000a">

<effect>

<onShow name=“fade” start="#0" end="#a" length=“200” inherit=“true” />

<onHide name=“fade” start="#a" end="#0" length=“200” startDelay=“100” inherit=“true” />

</effect>

/// my stuff



it shows the children below “my stuff” annotation. with out any issue… also im using a single controller and a single xml to show/hide all my stuff everywhere in my game: e.g console, main menu, in game menu and HUD. Doing so im not using multiple states and loading other xmls just one, and i fell in love with nifty after 1 hard day of understanding it :smiley:

I think ima do a tutorial on that.

@madjack: good point and it should work the same when show() is called on that layer because you are right, that show() will show the child elements too. I tried it here and it works as expected. I don’t see anything in the code that would prevent that behaviour. So maybe the Nifty of tobi82 is maybe too old or not the one from svn or there is something different that I don’t see? I have no idea. It worked here with calling show on the layer too …



However the expected way is to show()/hide() individual windows and not the whole layer.

well, it does work now, in all ways mentioned.

the newest nifty built did the trick. mine was 3 weeks old and i thought that was new enough.



is there any easy way to change the color/appearence of the draggable window?



and as always, thank you guys :slight_smile:

@tobi82

You can extract the style definition of the window control and fix it to suit your needs. That’s what I’m currently doing for my game.



You also might want to check and modify the window control definition to better suit your graphics, etc.

sure :slight_smile: start with the nifty-style-black project and find the nifty-window.xml:



[xml]<?xml version="1.0" encoding="UTF-8"?>

<nifty-styles>

<style id="nifty-window#frame">

<effect>

<onActive name="border" post="true" color="#2226" border="2px" />

</effect>

</style>



<style id="nifty-window#bar">

<attributes width="100%" height="20px" padding="2px" backgroundColor="#333f" childLayout="horizontal" />

</style>



<style id="nifty-window#title" base="base-font">

<attributes width="" height="20px" align="center" valign="center" textHAlign="center" textVAlign="center" visibleToMouse="false" color="#ffff" />

</style>



<style id="nifty-window#content">

<attributes width="100%" height="
" padding="8px" backgroundColor="#9996" childLayout="center" />

</style>



<style id="nifty-window#close-button">

<attributes backgroundImage="window/window-close-button.png" width="14px" height="14px" align="center" valign="center" />

<effect>

<onHover name="imageOverlayPulsate" filename="window/window-close-button-hover.png" post="true" />

</effect>

</style>

</nifty-styles>[/xml]



you have two options to modify this file:


  • make your own copy and include it after you've included the standard styles. something like [xml]<useStyles filename="nifty-default-styles.xml" />
    <useStyles filename="my-own-copy-of-nifty-window.xml" />[/xml]

  • make your own copy, include it and change "nifty-window" to "my-nifty-window" or some other name. you should then be able to apply that style to the window control ... style="my-nifty-window"