Hello. First of all, sorry for my bad English, I'm using a translator.
I'm looking for ways to create radio buttons and checkboxes based on default AGS GUI elements.
Looks like i have two problems.
- I can't add custom parameters for GUI elements from editor
- I can't change button's graphic
After searching for information, I found a couple of options that I can use
- Create GUI with ImGi Module. Looks flexible, but not sure if it can be a replacement for the standard GUI
OR
- Theoretically, i can write structure, that can store paramaters of checkboxes/radiobuttons, and array of DynamicSprite, to draw image based on "checkbox"'s state (checked/unchecked).
So, if someone has already dealt with a similar issue, can you tell me how you did it? Am I moving in the right direction?
The most basic way is to change the text of a button and store the state in a variable:
Create a button and add the OnClick event to the button by double clicking it in the GUI editor.
The script editor will open to a new function in the global script like function btnName_OnClick(GUIControl *control, MouseButton button)
Put this directly above the function:
bool activated = false;
Now put this inside:
if (button != eMouseLeft) return; // handle only left-clicks
activated = !activated;
Button *b = control.Asbutton;
if (activated) b.Text = "Active";
else b.Text = "Disabled";
You can expand this to your liking, i.e. change other buttons, change the image they use (no ImGi necessary for that), etc.
Quote from: hit3nkuro on Mon 15/08/2022 09:21:40
I can't change button's graphic
Not sure what you mean by that, but it is possible to change button's graphic in script using NormalGraphic property.
https://adventuregamestudio.github.io/ags-manual/Button.html#buttonnormalgraphic
As of the latest version GUI cannot have custom properties attached to them, so if using Text (as suggested by Khris above) does not work for you, you'll have to store extra properties in script. You can write structs. Also you can try using Dictionary and Set objects:
https://adventuregamestudio.github.io/ags-manual/Dictionary.html
https://adventuregamestudio.github.io/ags-manual/Set.html
Quote from: Crimson Wizard on Mon 15/08/2022 11:44:25
Not sure what you mean by that, but it is possible to change button's graphic in script using NormalGraphic property.
https://adventuregamestudio.github.io/ags-manual/Button.html#buttonnormalgraphic
Oh... Looks like i must spend a bit more time to reading manual. Anyway, thank you, this is exactly what I needed