Skip to content

Commit dd7f921

Browse files
committed
Bring menu item guide up to date.
1 parent 5184e27 commit dd7f921

File tree

1 file changed

+49
-50
lines changed

1 file changed

+49
-50
lines changed
Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
11
# Adding a RetroArch menu option
22

3+
The RetroArch menu system is a bit complex as no UI framework is used for implementing it, due to extreme portability reasons. This guide outlines adding one setting to RetroArch global configuration and the corresponding menu entry, but you may encounter special menus or more complex settings. Try to add the new bits to places where they can be logically found.
4+
35
## Files you need to change
46

5-
msg_hash_us.c
6-
msg_hash_us.h
7-
msg_hash_\*\*.c (If you speak more than one language)
8-
msg_hash_\*\*.h (If you speak more than one language)
9-
msg_hash_lbl.h
10-
msg_hash.h
11-
menu_cbs_sublabel.c
12-
menu_setting.c
13-
menu_displaylist.c
14-
configuration.c
15-
configuration.h
16-
config.def.h
17-
18-
## Creating the menu variable
19-
20-
For this example the variable will be an int named test_menu_option.
21-
22-
1. Open config.def.h
23-
2. Add `static const int test_menu_option = 0;` the 0 can be any number, this is just the default value, the user will change it later.
24-
3. Open configuration.h
25-
4. There are sections for each variable type(string, float, int, uint and bool) go to "ints" and add `int test_menu_option;`
26-
5. Open configuration.c
27-
6. Add `SETTING_INT("test_menu_option", &settings->ints.test_menu_option, true, test_menu_option, false);` to populate_settings_int.
28-
29-
The variable is now setup but the menu still doesnt know it exists.
30-
31-
## Making the menu read the variable
32-
33-
The variables name must now be configured
34-
35-
1. Open msg_hash.h
36-
2. Add `MENU_LABEL(TEST_MENU_OPTION)` to `enum msg_hash_enums`
37-
3. Open intl/msg_hash_lbl.h
38-
4. Add `MSG_HASH(MENU_ENUM_LABEL_TEST_MENU_OPTION, "test_menu_option")` in the `MENU_ENUM_LABEL_` section this is how RetroArch identifies the option.
39-
5. Open intl/msg_hash_us.h
40-
6. Add `MSG_HASH(MENU_ENUM_LABEL_VALUE_TEST_MENU_OPTION, "Test Menu Option")` in the `MENU_ENUM_LABEL_VALUE_` section this is what the user actually sees.
41-
7. Add `MSG_HASH(MENU_ENUM_SUBLABEL_TEST_MENU_OPTION, "Unused Text")` in the `MENU_ENUM_SUBLABEL_` section, sublabels are only used by xmb and glui, they are unused by rgui.
42-
8. Open intl/msg_hash_us.c
43-
9. Add `case MENU_ENUM_LABEL_TEST_MENU_OPTION: snprintf(s, len, "Help text"); break;` to `menu_hash_get_help_us_enum` this is the variable info that is shown when you push rshift.
7+
* `msg_hash_us.h`
8+
* `msg_hash_lbl.h`
9+
* `msg_hash.h`
10+
* `menu_cbs_sublabel.c`
11+
* `menu_setting.c`
12+
* `menu_displaylist.c`
13+
* `configuration.c`
14+
* `configuration.h`
15+
* `config.def.h`
16+
* `ui/drivers/qt/qt_options.cpp`
17+
18+
19+
## Creating the config variable
20+
21+
For this example the variable will be a boolean option for showing messages about failed autoconfig. You can also view the pull request [here](https://github.com/libretro/RetroArch/pull/17636/files).
22+
23+
1. Open `config.def.h`
24+
2. Add `#define DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG_FAILS true` to provide a generic default for the option. If needed, use compiler switches for different defaults on different platforms.
25+
3. Open `configuration.h`
26+
4. There are sections for each variable type(string, float, int, uint and bool) go to `bools` and add `bool notification_show_autoconfig_fails;`
27+
5. Open `configuration.c`
28+
6. Add `SETTING_BOOL("notification_show_autoconfig_fails", &settings->bools.notification_show_autoconfig_fails, true, DEFAULT_NOTIFICATION_SHOW_AUTOCONFIG_FAILS, false);` to `populate_settings_bool`.
29+
30+
The variable is now part of global RetroArch settings, will be saved/loaded from configuration file and can be used from RetroArch code, but the menu still doesn't know it exists.
31+
32+
## Defining menu labels and messages
33+
34+
Time to define the labels for identifying and displaying the new setting.
35+
36+
1. Open `msg_hash.h`
37+
2. Add `MENU_LABEL(NOTIFICATION_SHOW_AUTOCONFIG_FAILS)` to `enum msg_hash_enums`
38+
3. Open `intl/msg_hash_lbl.h`
39+
4. Add `MSG_HASH( MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS, "notification_show_autoconfig_fails")` in the `MENU_ENUM_LABEL_` section. This identifier may appear in logs, but not in the menu.
40+
5. Open `intl/msg_hash_us.h`
41+
6. Add `MSG_HASH( MENU_ENUM_LABEL_VALUE_NOTIFICATION_SHOW_AUTOCONFIG_FAILS, "Input (Autoconfig) Failure Notifications")` in the `MENU_ENUM_LABEL_VALUE_` section. This is what the user and the translators actually see.
42+
7. Add `MSG_HASH( MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS, "Display an on-screen message when input devices could not be configured.")` section. Sublabels are a bit more detailed explanations that appear underneath the menu item.
4443

4544
The option is now defined but the menu has still not been told to display it.
4645

4746
## Displaying your option
4847

4948
Now the menu has to be told how to display the option.
5049

51-
1. Open menu/cbs/menu_cbs_sublabel.c
52-
2. Add `default_sublabel_macro(action_bind_sublabel_test_menu_option, MENU_ENUM_SUBLABEL_TEST_MENU_OPTION)` to the block of `default_sublabel_macro` functions.
53-
3. Add `case MENU_ENUM_LABEL_TEST_MENU_OPTION: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_test_menu_option); break;` to the `menu_cbs_init_bind_sublabel` function.
54-
4. Open menu/menu_setting.c
55-
5. Find your variables section(saving, netplay, video, ...) and add `CONFIG_INT(list, list_info, &settings->ints.test_menu_option, MENU_ENUM_LABEL_TEST_MENU_OPTION, MENU_ENUM_LABEL_VALUE_TEST_MENU_OPTION, test_menu_option, &group_info, &subgroup_info, parent_group, general_write_handler, general_read_handler);` the menu knows everything it needs now.
56-
6. Open menu/menu_displaylist.c
57-
7. Find your variables section and add `menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_TEST_MENU_OPTION, PARSE_ONLY_INT, false);` the position of this command in the list is what determines the order of the menu entries, the first run is at the top of the list.
50+
1. Open `menu/cbs/menu_cbs_sublabel.c`
51+
2. Add `DEFAULT_SUBLABEL_MACRO( action_bind_sublabel_notification_show_autoconfig_fails, MENU_ENUM_SUBLABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS)` to the block of `DEFAULT_SUBLABEL_MACRO` functions.
52+
3. Add `case MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_notification_show_autoconfig_fails); break;` to the `menu_cbs_init_bind_sublabel` function.
53+
4. Open `menu/menu_setting.c`
54+
5. Find your variables section(saving, netplay, video, ...) and add `CONFIG_BOOL` macro. The options are too numerous to list here, look for a similar example to what you plan to add. This entry controls the related setting, the menu labels, and possible actions. Simple config types already have implemented actions for changing (like toggling the boolean value with left/right), but if something more complex is needed, like a list of predefined values, it will need to be implemented in other menu files.
55+
6. Open `menu/menu_displaylist.c`
56+
7. Find your variables section and add `{MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG_FAILS, PARSE_ONLY_BOOL, false },` the position of this command in the list is what determines the order of the menu entries, the first run is at the top of the list.
57+
8. Open `ui/drivers/qt/qt_options.cpp`
58+
9. Find the corresponding menu and add the option, in this case `notificationsGroup->add(MENU_ENUM_LABEL_NOTIFICATION_SHOW_AUTOCONFIG);`. This represents the menu item in the desktop menu.
5859

5960
# Finishing
6061

61-
There may be slight differences between variable types but for the most part if you want a string or bool just swap where ever you saw int for string or bool.
62-
63-
The variables name always follows the same format just replace test_menu_option, TEST_MENU_OPTION and "Test Menu Option" with your variables actual name in the same format of uppercase, lowercase or string.
62+
This guide only introduces the English menu labels. Translations are handled via Crowdin, after the pull request is accepted, new strings will appear for translators. New items wil be shown to users in English until translation is done.
6463

65-
This guide only effects the menu variables and the english name, if you speak another language do what you did to intl/msg_hash_us.c/h to your language files as well.
64+
There are several possibilities that can be done with the menu system, but most require additional functions. Help text may also be defined (a slightly longer description that can be displayed with Select button). Some of the menu code is dynamic depending on e.g. number of users, those items usually require extra care. Icon assignments are handled in the menu drivers (ozone, xmb, glui).

0 commit comments

Comments
 (0)