How can I make a button change appearance when I click on it, and keep it changed until I click on another GUI button.Ã, The "pushed image" function only changes the appearance of the button while I click on it, and that's not what I want.
Quote from: The Manual
NormalGraphic property (button)
(Formerly part of GetButtonPic, which is now obsolete)
(Formerly part of SetButtonPic, which is now obsolete)
int Button.NormalGraphic;
Gets/sets the button's normal sprite (ie. the graphic used when the button is not pushed and the mouse is not over it).
Note that setting this to a different sprite will change the button's size to match the size of the new sprite.
Use this to change the buttons graphic when you click it. You'll also need a
GUIControl pointer (http://www.adventuregamestudio.co.uk/manual/Pointers.htm) (specificly a
Button pointer) - to store the last button pressed - and an
int - for it's default normal graphic - for when you push the next button, and want to reset the graphic.
You might be better creating a function, to save having to write out the code for every button.
I found the script function(NormalGraphic property) in the manual, but I don't know how to use it.
This is what the manual tells me:
Quote from: The Manual
Example:
Display("The button's normal image is sprite %d.", btnPlay.NormalGraphic);
I don't understand the example. What am IÃ, supposed to write exactly?
That example is a little misleading for what you want to do, as it deals with getting the sprite number, rather than setting it (that's why I didn't include it in the quote).
Supposing the button was called btnTest, when you click on the button, you'd use:
btnTest.NormalGraphic = btnTest.PushedGraphic; // Or, if you know the spriteslot of the graphic, just use the number.
to make it stay as the pushed graphic after you release the mouse button.
To reset it when you push another button (make the first button 'pop up' again), you'll need something to store the last button pressed (a pointer) and an int to store what the normal graphic should be.
Okay, I have half of it working. The button changes appearance, and stays that way when I release the mouse button.Ã, Now, I'm having trouble with the "go back to normal when I click on another button" part. I'm kinda new with pointers and that kind of stuff.
Let's just say that the button's name is btnTest. This is what I would do in the Global script:
#sectionend btnTest_ClickÃ, // DO NOT EDIT OR REMOVE THIS LINE
function btnTest_Click(GUIControl *control, MouseButton button) {
btnTest.NormalGraphic = btnTest.PushedGraphic;
}
Now, according to what I have done, what would I do next to make the button go back to normal when I click on another button (let's call that button: btnOther)
QuoteYou'll also need a GUIControl pointer (specificly a Button pointer) - to store the last button pressed - and an int - for it's default normal graphic
So, up at the top of the global script:
Button *LastButton;
int LastGraphic;
That's your
Button pointer and int (the actual names don't matter, provided you use the same ones throughout).
Then:
function btnTest_Click(GUIControl *control, MouseButton button) {
if (LastButton != null) { // Reset previous button, but only if there WAS one
LastButton.NormalGraphic = LastGraphic;
}
LastGraphic = btnTest.NormalGraphic; // Store normal spriteslot
LastButton = btnTest;
btnTest.NormalGraphic = btnTest.PushedGraphic;
// Whatever else you want the button to do...
}
function btnOther_Click(GUIControl *control, MouseButton button) {
if (LastButton != null) { // Reset previous button, but only if there WAS one
LastButton.NormalGraphic = LastGraphic;
}
LastGraphic = btnOther.NormalGraphic; // Store normal spriteslot
LastButton = btnOther;
btnOther.NormalGraphic = btnOther.PushedGraphic;
// Whatever else you want the button to do...
}
// Etc...
But typing that code (or even copy-pasting it) is kind of repeatative & sloppy, so you could make a custom function, something like (at the top of the global script, before all the GUI control functions):
function HoldDown(Button *Pressed) {
if (LastButton != null) { // Reset previous button, but only if there WAS one
// Reset LastButton's graphic)
LastButton.NormalGraphic = LastGraphic;
}
LastButton = Pressed;
LastGraphic = Pressed.NormalGraphic;
Pressed.NormalGraphic = Pressed.PushedGraphic;
}
Then you just need to do:
function btnTest_Click(GUIControl *control, MouseButton button) {
HoldDown(btnTest);
// Whatever else you want the button to do...
}
function btnOther_Click(GUIControl *control, MouseButton button) {
HoldDown(btnOther);
// Whatever else you want the button to do...
}
// Etc...
NOTE:
HoldDown(control); will work for any button, just paste it in.
Finaly,Ã, it's working!!
;) Thanks Ashen,Ã, I couldn't have done It without your help.