Implement easy on/off options, and refactor for easier future new options/reordering

This commit is contained in:
Lorenzooone 2024-05-12 04:33:31 +02:00
parent 8c526e3747
commit a4daf7186a
4 changed files with 205 additions and 45 deletions

View File

@ -8,13 +8,17 @@
#include "sfml_gfx_structs.hpp"
#include "display_structs.hpp"
#define NUM_TOTAL_MAIN_MENU_OPTIONS 4
enum MainMenuOutAction{
MAIN_MENU_NO_ACTION,
MAIN_MENU_OPEN,
MAIN_MENU_CLOSE_MENU,
MAIN_MENU_QUIT_APPLICATION,
MAIN_MENU_FULLSCREEN,
MAIN_MENU_SPLIT,
MAIN_MENU_VSYNC,
MAIN_MENU_ASYNC,
MAIN_MENU_BLUR,
MAIN_MENU_PADDING,
};
class MainMenu : public OptionSelectionMenu {
@ -31,7 +35,7 @@ protected:
std::string get_string_option(int index);
void class_setup();
private:
int options_indexes[NUM_TOTAL_MAIN_MENU_OPTIONS];
int *options_indexes;
int num_enabled_options;
};
#endif

View File

@ -113,7 +113,13 @@ private:
int get_screen_corner_modifier_y(int rotation, int height);
void print_notification_on_off(std::string base_text, bool value);
void print_notification_float(std::string base_text, float value, int decimals);
void split_change();
void fullscreen_change();
void async_change();
void vsync_change();
void blur_change();
void poll_window();
void padding_change();
bool common_poll(SFEvent &event_data);
bool main_poll(SFEvent &event_data);
bool no_menu_poll(SFEvent &event_data);

View File

@ -1,19 +1,111 @@
#include "MainMenu.hpp"
static std::string main_menu_option_strings[NUM_TOTAL_MAIN_MENU_OPTIONS] = {"Disconnect", "Connect", "Close Menu", "Quit Application"};
static bool usable_fullscreen[NUM_TOTAL_MAIN_MENU_OPTIONS] = {true, false, true, true};
static bool usable_normal_screen[NUM_TOTAL_MAIN_MENU_OPTIONS] = {true, false, true, true};
static bool usable_joint_screen[NUM_TOTAL_MAIN_MENU_OPTIONS] = {true, false, true, true};
static bool usable_top_screen[NUM_TOTAL_MAIN_MENU_OPTIONS] = {true, false, true, true};
static bool usable_bottom_screen[NUM_TOTAL_MAIN_MENU_OPTIONS] = {true, false, true, true};
static MainMenuOutAction main_menu_out_actions[NUM_TOTAL_MAIN_MENU_OPTIONS] = {MAIN_MENU_OPEN, MAIN_MENU_NO_ACTION, MAIN_MENU_CLOSE_MENU, MAIN_MENU_QUIT_APPLICATION};
#define NUM_TOTAL_MAIN_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
#define OPTION_WINDOWED true
#define OPTION_FULLSCREEN true
#define OPTION_JOIN true
#define OPTION_SPLIT true
struct MainMenuOptionInfo {
const std::string base_name;
const std::string false_name;
const bool active_fullscreen;
const bool active_windowed_screen;
const bool active_joint_screen;
const bool active_top_screen;
const bool active_bottom_screen;
const MainMenuOutAction out_action;
};
static const MainMenuOptionInfo connect_option = {
.base_name = "Disconnect", .false_name = "Connect",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_OPEN};
static const MainMenuOptionInfo windowed_option = {
.base_name = "Windowed Mode", .false_name = "",
.active_fullscreen = OPTION_WINDOWED, .active_windowed_screen = false,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_FULLSCREEN};
static const MainMenuOptionInfo fullscreen_option = {
.base_name = "Fullscreen Mode", .false_name = "",
.active_fullscreen = false, .active_windowed_screen = OPTION_FULLSCREEN,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_FULLSCREEN};
static const MainMenuOptionInfo join_screens_option = {
.base_name = "Join Screens", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = false, .active_top_screen = OPTION_JOIN, .active_bottom_screen = OPTION_JOIN,
.out_action = MAIN_MENU_SPLIT};
static const MainMenuOptionInfo split_screens_option = {
.base_name = "Split Screens", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = OPTION_SPLIT, .active_top_screen = false, .active_bottom_screen = false,
.out_action = MAIN_MENU_SPLIT};
static const MainMenuOptionInfo vsync_option = {
.base_name = "Turn VSync Off", .false_name = "Turn VSync On",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_VSYNC};
static const MainMenuOptionInfo async_option = {
.base_name = "Turn Async Off", .false_name = "Turn Async On",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_ASYNC};
static const MainMenuOptionInfo blur_option = {
.base_name = "Turn Blur Off", .false_name = "Turn Blur On",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_BLUR};
static const MainMenuOptionInfo padding_option = {
.base_name = "Turn Padding Off", .false_name = "Turn Padding On",
.active_fullscreen = false, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_PADDING};
static const MainMenuOptionInfo close_option = {
.base_name = "Close Menu", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_CLOSE_MENU};
static const MainMenuOptionInfo quit_option = {
.base_name = "Quit Application", .false_name = "",
.active_fullscreen = true, .active_windowed_screen = true,
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
.out_action = MAIN_MENU_QUIT_APPLICATION};
static const MainMenuOptionInfo* pollable_options[] = {
&connect_option,
&windowed_option,
&fullscreen_option,
&join_screens_option,
&split_screens_option,
&vsync_option,
&async_option,
&blur_option,
&padding_option,
&close_option,
&quit_option
};
MainMenu::MainMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
this->options_indexes = new int[NUM_TOTAL_MAIN_MENU_OPTIONS];
this->initialize(font_load_success, text_font);
this->num_enabled_options = 0;
}
MainMenu::~MainMenu() {
delete []this->options_indexes;
}
void MainMenu::class_setup() {
@ -35,17 +127,20 @@ void MainMenu::class_setup() {
}
void MainMenu::insert_data(ScreenType s_type, bool is_fullscreen) {
bool *fullscreen_enabled_ptr = usable_fullscreen;
if(!is_fullscreen)
fullscreen_enabled_ptr = usable_normal_screen;
bool *screen_type_enabled_ptr = usable_joint_screen;
if(s_type == ScreenType::TOP)
screen_type_enabled_ptr = usable_top_screen;
if(s_type == ScreenType::BOTTOM)
screen_type_enabled_ptr = usable_bottom_screen;
this->num_enabled_options = 0;
for(int i = 0; i < NUM_TOTAL_MAIN_MENU_OPTIONS; i++) {
if(fullscreen_enabled_ptr[i] && screen_type_enabled_ptr[i]) {
bool valid = true;
if(is_fullscreen)
valid = valid && pollable_options[i]->active_fullscreen;
else
valid = valid && pollable_options[i]->active_windowed_screen;
if(s_type == ScreenType::TOP)
valid = valid && pollable_options[i]->active_top_screen;
else if(s_type == ScreenType::BOTTOM)
valid = valid && pollable_options[i]->active_bottom_screen;
else
valid = valid && pollable_options[i]->active_joint_screen;
if(valid) {
this->options_indexes[this->num_enabled_options] = i;
this->num_enabled_options++;
}
@ -58,7 +153,7 @@ void MainMenu::reset_output_option() {
}
void MainMenu::set_output_option(int index) {
this->selected_index = main_menu_out_actions[this->options_indexes[index]];
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
}
int MainMenu::get_num_options() {
@ -66,13 +161,13 @@ int MainMenu::get_num_options() {
}
std::string MainMenu::get_string_option(int index) {
return main_menu_option_strings[this->options_indexes[index]];
return pollable_options[this->options_indexes[index]]->base_name;
}
static std::string setTextOptionBool(int option_index, bool value) {
if(value)
return main_menu_option_strings[option_index];
return main_menu_option_strings[option_index + 1];
return pollable_options[option_index]->base_name;
return pollable_options[option_index]->false_name;
}
void MainMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info, bool connected) {
@ -84,10 +179,22 @@ void MainMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size
if(!this->future_enabled_labels[i])
continue;
int option_index = this->options_indexes[start + i];
switch(main_menu_out_actions[option_index]) {
switch(pollable_options[option_index]->out_action) {
case MAIN_MENU_OPEN:
this->labels[i]->setText(setTextOptionBool(option_index, connected));
break;
case MAIN_MENU_VSYNC:
this->labels[i]->setText(setTextOptionBool(option_index, info->v_sync_enabled));
break;
case MAIN_MENU_ASYNC:
this->labels[i]->setText(setTextOptionBool(option_index, info->async));
break;
case MAIN_MENU_BLUR:
this->labels[i]->setText(setTextOptionBool(option_index, info->is_blurred));
break;
case MAIN_MENU_PADDING:
this->labels[i]->setText(setTextOptionBool(option_index, info->rounded_corners_fix));
break;
default:
break;
}

View File

@ -94,6 +94,44 @@ void WindowScreen::reload() {
this->prepare_size_ratios(true, true);
}
void WindowScreen::split_change() {
if(this->curr_menu != CONNECT_MENU_TYPE)
this->curr_menu = DEFAULT_MENU_TYPE;
this->m_info.is_fullscreen = false;
this->display_data->split = !this->display_data->split;
}
void WindowScreen::fullscreen_change() {
if(this->curr_menu != CONNECT_MENU_TYPE)
this->curr_menu = DEFAULT_MENU_TYPE;
this->m_info.is_fullscreen = !this->m_info.is_fullscreen;
this->create_window(true);
}
void WindowScreen::async_change() {
this->m_info.async = !this->m_info.async;
this->print_notification_on_off("Async", this->m_info.async);
}
void WindowScreen::vsync_change() {
this->m_info.v_sync_enabled = !this->m_info.v_sync_enabled;
this->print_notification_on_off("VSync", this->m_info.v_sync_enabled);
}
void WindowScreen::blur_change() {
this->m_info.is_blurred = !this->m_info.is_blurred;
this->future_operations.call_blur = true;
this->print_notification_on_off("Blur", this->m_info.is_blurred);
}
void WindowScreen::padding_change() {
if(this->m_info.is_fullscreen)
return;
this->m_info.rounded_corners_fix = !this->m_info.rounded_corners_fix;
this->future_operations.call_screen_settings_update = true;
this->print_notification_on_off("Extra Padding", this->m_info.rounded_corners_fix);
}
bool WindowScreen::common_poll(SFEvent &event_data) {
double old_scaling = 0.0;
bool consumed = true;
@ -105,27 +143,19 @@ bool WindowScreen::common_poll(SFEvent &event_data) {
case sf::Event::TextEntered:
switch(event_data.unicode) {
case 's':
if(this->curr_menu != CONNECT_MENU_TYPE)
this->curr_menu = DEFAULT_MENU_TYPE;
this->m_info.is_fullscreen = false;
this->display_data->split = !this->display_data->split;
this->split_change();
break;
case 'f':
if(this->curr_menu != CONNECT_MENU_TYPE)
this->curr_menu = DEFAULT_MENU_TYPE;
this->m_info.is_fullscreen = !this->m_info.is_fullscreen;
this->create_window(true);
this->fullscreen_change();
break;
case 'a':
this->m_info.async = !this->m_info.async;
this->print_notification_on_off("Async", this->m_info.async);
this->async_change();
break;
case 'v':
this->m_info.v_sync_enabled = !this->m_info.v_sync_enabled;
this->print_notification_on_off("VSync", this->m_info.v_sync_enabled);
this->vsync_change();
break;
case 'z':
@ -307,9 +337,7 @@ bool WindowScreen::main_poll(SFEvent &event_data) {
break;
case 'b':
this->m_info.is_blurred = !this->m_info.is_blurred;
this->future_operations.call_blur = true;
this->print_notification_on_off("Blur", this->m_info.is_blurred);
this->blur_change();
break;
case 'i':
@ -401,12 +429,7 @@ bool WindowScreen::main_poll(SFEvent &event_data) {
break;
case 'r':
if(this->m_info.is_fullscreen)
break;
this->m_info.rounded_corners_fix = !this->m_info.rounded_corners_fix;
this->future_operations.call_screen_settings_update = true;
this->print_notification_on_off("Extra Padding", this->m_info.rounded_corners_fix);
this->padding_change();
break;
case '2':
@ -545,6 +568,26 @@ void WindowScreen::poll() {
this->curr_menu = DEFAULT_MENU_TYPE;
return;
break;
case MAIN_MENU_FULLSCREEN:
this->fullscreen_change();
return;
break;
case MAIN_MENU_SPLIT:
this->split_change();
return;
break;
case MAIN_MENU_VSYNC:
this->vsync_change();
break;
case MAIN_MENU_ASYNC:
this->async_change();
break;
case MAIN_MENU_BLUR:
this->blur_change();
break;
case MAIN_MENU_PADDING:
this->padding_change();
break;
default:
break;
}