-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MenuOption to change the menu options/settings. #471
Conversation
|
||
// change all settings as per options | ||
void set_options( | ||
std::vector<std::pair<MenuOptionItemEnum, std::vector<MenuOptionToggleEnum>>> options) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each MenuOptionItemEnum is paired with a vector MenuOptionToggleEnum. The reason for this is that the mapping for the options in each language is slightly different. e.g. For "Send to Boxes", the options may be Manual/Automatic in English, but may be On/Off in other languages.
Here is some example code from AutoStory:
void AutoStory::change_settings(SingleSwitchProgramEnvironment& env, BotBaseContext& context, bool use_inference){
env.console.log("Update settings.");
if (use_inference){
MenuOption session(env.console, context, LANGUAGE);
std::vector<std::pair<MenuOptionItemEnum, std::vector<MenuOptionToggleEnum>>> options = {
{MenuOptionItemEnum::TEXT_SPEED, {MenuOptionToggleEnum::FAST}},
{MenuOptionItemEnum::SKIP_MOVE_LEARNING, {MenuOptionToggleEnum::ON}},
{MenuOptionItemEnum::SEND_TO_BOXES, {MenuOptionToggleEnum::AUTOMATIC, MenuOptionToggleEnum::ON}},
{MenuOptionItemEnum::GIVE_NICKNAMES, {MenuOptionToggleEnum::OFF}},
{MenuOptionItemEnum::VERTICAL_CAMERA_CONTROLS, {MenuOptionToggleEnum::REGULAR, MenuOptionToggleEnum::NORMAL}},
{MenuOptionItemEnum::HORIZONTAL_CAMERA_CONTROLS, {MenuOptionToggleEnum::REGULAR, MenuOptionToggleEnum::NORMAL}},
{MenuOptionItemEnum::CAMERA_SUPPORT, {MenuOptionToggleEnum::ON}},
{MenuOptionItemEnum::CAMERA_INTERPOLATION, {MenuOptionToggleEnum::NORMAL, MenuOptionToggleEnum::AVERAGE}},
{MenuOptionItemEnum::CAMERA_DISTANCE, {MenuOptionToggleEnum::CLOSE}},
{MenuOptionItemEnum::AUTOSAVE, {MenuOptionToggleEnum::OFF}},
{MenuOptionItemEnum::SHOW_NICKNAMES, {MenuOptionToggleEnum::OFF, MenuOptionToggleEnum::DONT_SHOW}},
{MenuOptionItemEnum::SKIP_CUTSCENES, {MenuOptionToggleEnum::ON}},
{MenuOptionItemEnum::CONTROLLER_RUMBLE, {MenuOptionToggleEnum::ON}},
{MenuOptionItemEnum::HELPING_FUNCTIONS, {MenuOptionToggleEnum::OFF}},
};
session.set_options(options);
}else{
config_option(context, 1); // Text Speed: Fast
config_option(context, 1); // Skip Move Learning: On
config_option(context, 1); // Send to Boxes: Automatic
config_option(context, 1); // Give Nicknames: Off
config_option(context, 0); // Vertical Camera Controls: Regular
config_option(context, 0); // Horiztontal Camera Controls: Regular
config_option(context, 0); // Camera Support: On
config_option(context, 0); // Camera Interpolation: Normal
config_option(context, 0); // Camera Distance: Close
config_option(context, 1); // Autosave: Off
config_option(context, 1); // Show Nicknames: Don't show
config_option(context, 1); // Skip Cutscenes: On
config_option(context, 0); // Background Music: 10
config_option(context, 0); // Sound Effects: 10
config_option(context, 0); // Pokemon Cries: 10
config_option(context, 0); // Controller Rumble: On
config_option(context, 1); // Helping Functions: Off
}
pbf_mash_button(context, BUTTON_A, 1 * TICKS_PER_SECOND);
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 5);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in the case where there are multiple MenuOptionToggleEnum
, it means it can be either one depending on the language. Thus the program to should set it to which ever one it finds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The program keeps cycling the options, until it matches one of the option_toggles in the list.
03a4f23
to
e9826c0
Compare
// set the current selected option, to the given option_toggle | ||
// (which is a list of option_toggles, since the mapping for the options in each language is slightly different) | ||
void set_target_option( | ||
const std::vector<MenuOptionToggleEnum> target_option_toggle_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference
} | ||
|
||
void MenuOption::set_options( | ||
std::vector<std::pair<MenuOptionItemEnum, std::vector<MenuOptionToggleEnum>>> options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's several more places like this where you're copying a non-trivial parameter instead of passing by const-ref.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basic programming question: For the vector of MenuOptionToggleEnum, within the pair, do I need to also make this a reference as well? Or is this redundant since I'm already making options
pass by reference?
i.e.
const std::vector<std::pair<MenuOptionItemEnum, std::vector<MenuOptionToggleEnum>&>>& options
vs
const std::vector<std::pair<MenuOptionItemEnum, std::vector<MenuOptionToggleEnum>>>& options
Edit: Thinking about this some more, I believe option 2 is fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general rule of thumb for passing in read-only parameters is:
- If it's a primitive type (integer, float/double, pointer, enum): Pass by value. You don't need to mark it const because it's being copied and thus the function cannot affect the caller.
- If it's anything else, (struct, class, array, etc...): Pass by const reference. This avoids the copying the entire object since passing a reference is (internally), the same a passing a single pointer.
Of course exceptions will apply. Especially with async stuff where you have to watch out for the lifetimes of the objects.
std::string current_option_slug = read_option_item(); | ||
MenuOptionItem current_option = menu_option_item_lookup_by_slug(current_option_slug); | ||
|
||
MenuOptionItem target_option = menu_option_item_lookup_by_enum(target_option_enum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these can be const-ref instead of value to avoid copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change target_option to const ref. But not current_option, since it gets reassigned in the loop.
No description provided.