2 Adding MenuData items to a menu
combustiblelemonade edited this page 2021-12-01 01:15:50 +01:00

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)

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])