I'm trying to replace all my Displayed text by a custom message window GUI.
In order to get the window to close again, I thought of the following:
- Make an invisible button as large as the new message window.
- When the GUI opens, set mouse cursor to 6 (the pointer).
- When the user clicks on the huge button, close the window with GuiOff.
- Reset the cursor.
My problem now is that in order to display text on the window, I need a label, and apparently the label overrides the button, i.e. when I click on the window anywhere outside the text label, it closes, but when I click on the text, it doesn't recognize this as a click on the button.
This is what it looks like so far... the edges for the button are a bit hard to see because they're bright pink on a slightly darker pink, but the button basically spans the whole image, while the label text will go where the green letters say "1,2,3,etc" at the moment:
(http://www.2dadventure.com/ags/knetgui.jpg)
Is there a way to
a) either change some sort of z-order to put the label behind the button
or
b) another clever way of closing the window with a single mouse click?
EDIT:
As an alternative, I thought I might dispense with the button and just check on every mouse click if the GUI was open and if so, close it. So I added the line
{if (IsGUIOn(3)==1) GUIOff(3);}
to the function on_mouse_click for the left button. Nothing happened. Any idea why? I've tried it with both a clickable and a non-clickable GUI.
EDIT #2: The above works, but only if I put it right on top of the on_mouse_click function, even before the check for IsGamePaused. Now it reacts to left and right-clicks, which is not what I want.
Why can't I use
else if ((button==LEFT) && (IsGUIOn(3)))
{
GuiOff(3);
}
?
check for the GUI_MDOWN event in on_event and the just GUIOff?
Out of interest: Why don't you use the "Display messages on GUI" option on the main options page? This is explained in the help file.
SSH, as for the GUI_MDOWN event, I tried the following:
function on_event (int event, int data)
{
if(event==GUI_MDOWN && data==3)
{
GUIOff(3);
}
}
Am I doing anything wrong? Because it's not working.
(EDIT: Actually it IS working. No idea where I screwed up, I loaded an old backup copy and it worked. I'd still rather not force the player to click on the GUI, but ANY click should close it when it's open.)
About the "Text Windows use Gui #": I can't turn this image into a text file, because the borders wouldn't scale right and on the right upper and lower corner I'd run into trouble with the transparent bit. I kinda learned this lesson the hard way when I spent 5 hours on the problem last night instead of sleeping... :)
Well, if you want any click to close it and you dont mind blocking:
while (IsButtonPressed(LEFT)==0) {
Wait (1);
}
I tried that, but I need to insert some Waits so it won't react to the same click by opening and closing it again at once.
This was actually the technique I had used originally, but I thought "there must be a more elegant way..."
Apparently not. :) Thanks a lot for your help, though.
For now, I'll stick with the following:
GUIOn(3);
Wait(8);
while (IsButtonDown(LEFT)==0)
{Wait(1);}
GUIOff(3);
Wait(8);
Ah yes, for a full debounce:
while (IsButtonDown(LEFT)!=0) {Wait(1);}
while (IsButtonDown(LEFT)==0) {Wait(1);}
while (IsButtonDown(LEFT)!=0) {Wait(1);}
For more elegant, If you don't mind a timeout and keypresses closing it too, try:
WaitMouseKey(500);
Thanks, that did the trick!
I had also tried the WaitMouseKey one, with the number varying according to the length of the displayed text, but now I'm happy. ;D