Add 'Adding MenuData items to a menu'

master
combustiblelemonade 2021-12-01 01:11:26 +01:00
parent 85471b14cc
commit bcfa9f5165
1 changed files with 43 additions and 0 deletions

@ -0,0 +1,43 @@
In this article we will describe what steps need to be taken to add a menudata item to a menu. First, a menu data type needs to be chosen. Currently there are four: MenuColor, MenuCheckButton, MenuSlider, and MenuLineEdit. They are available as scenes in Assets/UI. Each MenuData object has a label and an index property. The label property is what is shown to the end user, and the index property is the key that is used to store data. These menu items can be added anywhere in a menu.
For this example we take a look at the "Glow" MenuCheckButton. When adding the checkbutton, we set the label and index accorddingly:
(TODO)
We also add a callback to on_glow_toggled, in GraphicsMenu.gd:
(TODO)
In this function we add the following code:
(TODO)
The function contains the following code:
```
func on_glow_toggled(button_pressed):
if GUI:
GUI.set_glow(button_pressed)
$Glow.save_data()
```
In the GUI object there is a function to set the glow:
```
func set_glow(is_enabled):
# TODO
pass
```
Now, all we need to do is call this function at startup too, so the value is initialized correctly. We do this in the apply_settings function in GUI.gd:
```
func apply_settings():
for key in settings.keys():
match key:
"Sensitivity":
set_mouse_sensitivity(settings[key])
(...)
"GraphicsGlow":
set_glow(settings[key])
```