[SOLVED] Clicking a few times on GUI button makes it disappear

Started by MonkeySyrup, Mon 16/03/2020 19:06:51

Previous topic - Next topic

TheManInBoots

Btw. MonkeySyrup,
great news, I have made a module called "Button Magic" that does all that automatically!

So with the module all you will have to write is this when clicking on the entire Gui:

Code: ags

function gGuiShelf_OnClick(GUI *theGui, MouseButton button)
{
MakeVisible(gGuiShelf);
}


(You have to define the gui that you use with all the book buttons on it (in this example gGuiShelf).

And then turn every button invisible when clicking on it:

Code: ags
function book1_OnClick(GUIControl *control, MouseButton button)
{
book1.Visible=false;
}

function book2_OnClick(GUIControl *control, MouseButton button)
{
book2.Visible=false;
}

function book3_OnClick(GUIControl *control, MouseButton button)
{
book3.Visible=false;
}

function book4_OnClick(GUIControl *control, MouseButton button)
{
book4.Visible=false;
}



When the function is run, the module automatically recognizes if the mouse is over an invisible button and if so turns that button visible.
It's very simple.

So now, buttons turn invisible when clicking on them, and back to visible when clicking again on where they were.

As it is, it works for Guis with no off-set. If your overall gui (the gGuiShelf in the example) has an off-set to the left and top you could tell me and I could add that, you would simply then have two function instead of the one (MakeVisible).

I sent the module link to your PM's.

It would be actually possible for you to write the ENTIRE thing in only 2 script lines, and absolutely nothing more, but I can't tell you about it because unfortunately there are people in this forum who would probably insult me if I did, because it wouldn't be the most conformal way.

Anyways, this will make things way easier for you.

I worked on something else and realized I could make this easily work for you, too, so there you go.

TheManInBoots

Quote from: TheManInBoots on Tue 17/03/2020 15:22:59
Yeah, I can imagine it's too much work for what you're trying to do.
Btw. you could trick your way around not being able to click a transparent button, by having one pixel drawn on the original empty sprite (that you use the method Crimson Wizard suggested) with 0.1 opacity/transparency for that one pixel in the image editor you use, and the rest transparent. It's a little bit under the table advice, but in case nothing else works...

Just for correction of what I wrote above:
One can click a button with a completely transparent sprite. As long as one has text written in the button text field, it works. And the text dissappears automatically anyways as soon as one adds a background image to the button.
So I wouldn't advice what I wrote in the quote anymore, and transparent buttons are perfectly possible.

SMF spam blocked by CleanTalk