In my current project I am trying to reposition an gui object every time I unhide it. If I unhide the object via gui button, everything is fine (the object gets a new position). But if I try to unhide the object via keyboard shortcut (for example “M”) the object is not reposition right after unhide. It takes about 4 seconds until the object reacts.
if (name.equalsIgnoreCase(“Market”) && !isPressed) {
GameManager.global_HUDMainScreen.windowControl(“show”, “”, “Economy”); //global_HUDMainScreen = static object of HUDMainScreen
//windowControl(“show”, “”, “Economy”) calls a method which includes the method which opens the recalc method (windowObject.internalMethod((“recalcPosition”))
}
I’m not sure there is enough code here to identify your problem. Since it works on button click but not when you hit a hotkey it suggests that it is a problem with your code path between hitting a hotkey and the code getting triggered. It maybe could be a threading issue? Not really sure without seeing more of your code since it looks like you are doing something very different with events and such.
windowObject.internalMethod((“recalcPosition”)); //that´s the relevant code
windowObject.internalMethod(“open”); //unimportant, only reloads the gui object related to text or color
nifty.getCurrentScreen().findElementByName(windowObject.getWindowName() + “-Main0”).show(); }
windowVisible only checks if the window is hiding at the moment.
windowObject.internalMethod((“recalcPosition”)) → that´s the part of the code which activate the recalc function:
This still isn’t enough to tell where your problem is. Your nifty code is correct and wouldn’t cause the delay you are experiencing. This is especially true if you are calling the same “recalcPosition” code on both mouse click and hotkey. I do that all the time in my code for hotkeys as well as mouse events.
You could try setting breakpoints in your code to verify your “recalcPosition” code is being called immediately. I would also verify that the call is taking place in the main thread. The only other thing I could think of is that somehow setting the position of your elements is conflicting with the show call but you would need to trace through the nifty code to verify that. You could try reversing the order for example.
Thanks I tried to go over the whole code again and I found the possible problem. If I hit the key and the window is unhiding, the window will only reposition it´s x,y if I move the mouse over a button. It has probably something to do with the rendering stuff, or?
Update: It has something to do with the mouse hover effect. If I disable the hover effect of the buttons, the window is not moving at all.
Update 2: Found the solution. I am so stupid… I had to replace parentWindow.layoutElements(); with screen.layoutLayers(); … well it make sense to do that and I don’t know why I tried to use the other method first. Anyway, thank you