mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-09-09 09:05:26 -05:00
Move Menus to subfolder
This commit is contained in:
133
source/Menus/AudioMenu.cpp
Executable file
133
source/Menus/AudioMenu.cpp
Executable file
@@ -0,0 +1,133 @@
|
||||
#include "AudioMenu.hpp"
|
||||
|
||||
#define NUM_TOTAL_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
|
||||
|
||||
struct AudioMenuOptionInfo {
|
||||
const std::string base_name;
|
||||
const std::string false_name;
|
||||
const bool is_inc;
|
||||
const std::string dec_str;
|
||||
const std::string inc_str;
|
||||
const AudioMenuOutAction inc_out_action;
|
||||
const AudioMenuOutAction out_action;
|
||||
};
|
||||
|
||||
static const AudioMenuOptionInfo audio_volume_option = {
|
||||
.base_name = "Volume", .false_name = "",
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = AUDIO_MENU_VOLUME_INC,
|
||||
.out_action = AUDIO_MENU_VOLUME_DEC};
|
||||
|
||||
static const AudioMenuOptionInfo audio_mute_option = {
|
||||
.base_name = "Unmute Audio", .false_name = "Mute Audio",
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = AUDIO_MENU_NO_ACTION,
|
||||
.out_action = AUDIO_MENU_MUTE};
|
||||
|
||||
static const AudioMenuOptionInfo audio_restart_option = {
|
||||
.base_name = "Restart Audio", .false_name = "",
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = AUDIO_MENU_NO_ACTION,
|
||||
.out_action = AUDIO_MENU_RESTART};
|
||||
|
||||
static const AudioMenuOptionInfo* pollable_options[] = {
|
||||
&audio_volume_option,
|
||||
&audio_mute_option,
|
||||
&audio_restart_option,
|
||||
};
|
||||
|
||||
AudioMenu::AudioMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->options_indexes = new int[NUM_TOTAL_MENU_OPTIONS];
|
||||
this->initialize(font_load_success, text_font);
|
||||
this->num_enabled_options = 0;
|
||||
}
|
||||
|
||||
AudioMenu::~AudioMenu() {
|
||||
delete []this->options_indexes;
|
||||
}
|
||||
|
||||
void AudioMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Audio Settings";
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void AudioMenu::insert_data() {
|
||||
this->num_enabled_options = 0;
|
||||
for(int i = 0; i < NUM_TOTAL_MENU_OPTIONS; i++) {
|
||||
this->options_indexes[this->num_enabled_options] = i;
|
||||
this->num_enabled_options++;
|
||||
}
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void AudioMenu::reset_output_option() {
|
||||
this->selected_index = AudioMenuOutAction::AUDIO_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void AudioMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = AUDIO_MENU_BACK;
|
||||
else if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->inc_out_action;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int AudioMenu::get_num_options() {
|
||||
return this->num_enabled_options;
|
||||
}
|
||||
|
||||
std::string AudioMenu::get_string_option(int index, int action) {
|
||||
if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->inc_str;
|
||||
if((action == DEC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->dec_str;
|
||||
return pollable_options[this->options_indexes[index]]->base_name;
|
||||
}
|
||||
|
||||
bool AudioMenu::is_option_inc_dec(int index) {
|
||||
return pollable_options[this->options_indexes[index]]->is_inc;
|
||||
}
|
||||
|
||||
static std::string setTextOptionInt(int option_index, int value) {
|
||||
return pollable_options[option_index]->base_name + ": " + std::to_string(value);
|
||||
}
|
||||
|
||||
static std::string setTextOptionBool(int option_index, bool value) {
|
||||
if(value)
|
||||
return pollable_options[option_index]->base_name;
|
||||
return pollable_options[option_index]->false_name;
|
||||
}
|
||||
|
||||
void AudioMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, AudioData *audio_data) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int option_index = this->options_indexes[start + i];
|
||||
switch(pollable_options[option_index]->out_action) {
|
||||
case AUDIO_MENU_VOLUME_DEC:
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, audio_data->get_real_volume()));
|
||||
break;
|
||||
case AUDIO_MENU_MUTE:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, audio_data->get_mute()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
49
source/Menus/ConnectionMenu.cpp
Executable file
49
source/Menus/ConnectionMenu.cpp
Executable file
@@ -0,0 +1,49 @@
|
||||
#include "ConnectionMenu.hpp"
|
||||
|
||||
ConnectionMenu::ConnectionMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->initialize(font_load_success, text_font);
|
||||
}
|
||||
|
||||
ConnectionMenu::~ConnectionMenu() {
|
||||
}
|
||||
|
||||
void ConnectionMenu::class_setup() {
|
||||
this->num_options_per_screen = 4;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 10;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Connection Menu";
|
||||
this->show_back_x = false;
|
||||
this->show_x = false;
|
||||
this->show_title = false;
|
||||
}
|
||||
|
||||
void ConnectionMenu::insert_data(DevicesList *devices_list) {
|
||||
this->devices_list = devices_list;
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void ConnectionMenu::reset_output_option() {
|
||||
this->selected_index = -1;
|
||||
}
|
||||
|
||||
void ConnectionMenu::set_output_option(int index, int action) {
|
||||
this->selected_index = index;
|
||||
}
|
||||
|
||||
int ConnectionMenu::get_num_options() {
|
||||
return this->devices_list->numValidDevices;
|
||||
}
|
||||
|
||||
std::string ConnectionMenu::get_string_option(int index, int action) {
|
||||
return std::string(&this->devices_list->serialNumbers[SERIAL_NUMBER_SIZE * index]);
|
||||
}
|
||||
|
||||
void ConnectionMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y) {
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
66
source/Menus/CropMenu.cpp
Executable file
66
source/Menus/CropMenu.cpp
Executable file
@@ -0,0 +1,66 @@
|
||||
#include "CropMenu.hpp"
|
||||
|
||||
CropMenu::CropMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->initialize(font_load_success, text_font);
|
||||
}
|
||||
|
||||
CropMenu::~CropMenu() {
|
||||
}
|
||||
|
||||
void CropMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Crop Settings";
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void CropMenu::insert_data(std::vector<const CropData*>* possible_crops) {
|
||||
this->possible_crops = possible_crops;
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void CropMenu::reset_output_option() {
|
||||
this->selected_index = CROP_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void CropMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = CROP_MENU_BACK;
|
||||
else
|
||||
this->selected_index = index;
|
||||
}
|
||||
|
||||
int CropMenu::get_num_options() {
|
||||
return (*this->possible_crops).size();
|
||||
}
|
||||
|
||||
std::string CropMenu::get_string_option(int index, int action) {
|
||||
return (*this->possible_crops)[index]->name;
|
||||
}
|
||||
|
||||
void CropMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, int current_crop) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int crop_index = start + i;
|
||||
if(crop_index == current_crop)
|
||||
this->labels[index]->setText("<" + (*this->possible_crops)[crop_index]->name + ">");
|
||||
else
|
||||
this->labels[index]->setText((*this->possible_crops)[crop_index]->name);
|
||||
}
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
218
source/Menus/MainMenu.cpp
Executable file
218
source/Menus/MainMenu.cpp
Executable file
@@ -0,0 +1,218 @@
|
||||
#include "MainMenu.hpp"
|
||||
|
||||
#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
|
||||
#define OPTION_EXTRA false
|
||||
#define OPTION_QUIT true
|
||||
#define OPTION_SHUTDOWN false
|
||||
|
||||
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 video_settings_option = {
|
||||
.base_name = "Video Settings", .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_VIDEO_SETTINGS};
|
||||
|
||||
static const MainMenuOptionInfo quit_option = {
|
||||
.base_name = "Quit Application", .false_name = "",
|
||||
.active_fullscreen = OPTION_QUIT, .active_windowed_screen = OPTION_QUIT,
|
||||
.active_joint_screen = OPTION_QUIT, .active_top_screen = OPTION_QUIT, .active_bottom_screen = OPTION_QUIT,
|
||||
.out_action = MAIN_MENU_QUIT_APPLICATION};
|
||||
|
||||
static const MainMenuOptionInfo shutdown_option = {
|
||||
.base_name = "Shutdown", .false_name = "",
|
||||
.active_fullscreen = OPTION_SHUTDOWN, .active_windowed_screen = OPTION_SHUTDOWN,
|
||||
.active_joint_screen = OPTION_SHUTDOWN, .active_top_screen = OPTION_SHUTDOWN, .active_bottom_screen = OPTION_SHUTDOWN,
|
||||
.out_action = MAIN_MENU_SHUTDOWN};
|
||||
|
||||
static const MainMenuOptionInfo audio_settings_option = {
|
||||
.base_name = "Audio Settings", .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_AUDIO_SETTINGS};
|
||||
|
||||
static const MainMenuOptionInfo save_profiles_option = {
|
||||
.base_name = "Save Profile", .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_SAVE_PROFILES};
|
||||
|
||||
static const MainMenuOptionInfo load_profiles_option = {
|
||||
.base_name = "Load Profile", .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_LOAD_PROFILES};
|
||||
|
||||
static const MainMenuOptionInfo status_option = {
|
||||
.base_name = "Status", .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_STATUS};
|
||||
|
||||
static const MainMenuOptionInfo licenses_option = {
|
||||
.base_name = "Licenses", .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_LICENSES};
|
||||
|
||||
static const MainMenuOptionInfo extra_settings_option = {
|
||||
.base_name = "Extra Settings", .false_name = "",
|
||||
.active_fullscreen = OPTION_EXTRA, .active_windowed_screen = OPTION_EXTRA,
|
||||
.active_joint_screen = OPTION_EXTRA, .active_top_screen = OPTION_EXTRA, .active_bottom_screen = OPTION_EXTRA,
|
||||
.out_action = MAIN_MENU_EXTRA_SETTINGS};
|
||||
|
||||
static const MainMenuOptionInfo* pollable_options[] = {
|
||||
&connect_option,
|
||||
&windowed_option,
|
||||
&fullscreen_option,
|
||||
&join_screens_option,
|
||||
&split_screens_option,
|
||||
&video_settings_option,
|
||||
&audio_settings_option,
|
||||
&save_profiles_option,
|
||||
&load_profiles_option,
|
||||
&extra_settings_option,
|
||||
&status_option,
|
||||
&licenses_option,
|
||||
&quit_option,
|
||||
&shutdown_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() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Main Menu";
|
||||
this->show_back_x = true;
|
||||
this->show_x = true;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void MainMenu::insert_data(ScreenType s_type, bool is_fullscreen) {
|
||||
this->num_enabled_options = 0;
|
||||
for(int i = 0; i < NUM_TOTAL_MAIN_MENU_OPTIONS; 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++;
|
||||
}
|
||||
}
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void MainMenu::reset_output_option() {
|
||||
this->selected_index = MainMenuOutAction::MAIN_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void MainMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = MAIN_MENU_CLOSE_MENU;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int MainMenu::get_num_options() {
|
||||
return this->num_enabled_options;
|
||||
}
|
||||
|
||||
std::string MainMenu::get_string_option(int index, int action) {
|
||||
return pollable_options[this->options_indexes[index]]->base_name;
|
||||
}
|
||||
|
||||
static std::string setTextOptionBool(int option_index, bool value) {
|
||||
if(value)
|
||||
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, bool connected) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int option_index = this->options_indexes[start + i];
|
||||
switch(pollable_options[option_index]->out_action) {
|
||||
case MAIN_MENU_OPEN:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, connected));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
138
source/Menus/OffsetMenu.cpp
Executable file
138
source/Menus/OffsetMenu.cpp
Executable file
@@ -0,0 +1,138 @@
|
||||
#include "OffsetMenu.hpp"
|
||||
|
||||
#define NUM_TOTAL_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
|
||||
|
||||
struct OffsetMenuOptionInfo {
|
||||
const std::string base_name;
|
||||
const bool is_inc;
|
||||
const std::string dec_str;
|
||||
const std::string inc_str;
|
||||
const OffsetMenuOutAction inc_out_action;
|
||||
const OffsetMenuOutAction out_action;
|
||||
};
|
||||
|
||||
static const OffsetMenuOptionInfo small_screen_offset_option = {
|
||||
.base_name = "Screens Offsets",
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = OFFSET_MENU_SMALL_OFFSET_INC,
|
||||
.out_action = OFFSET_MENU_SMALL_OFFSET_DEC};
|
||||
|
||||
static const OffsetMenuOptionInfo subscreen_distance_option = {
|
||||
.base_name = "Sub-Screen Distance",
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = OFFSET_MENU_SMALL_SCREEN_DISTANCE_INC,
|
||||
.out_action = OFFSET_MENU_SMALL_SCREEN_DISTANCE_DEC};
|
||||
|
||||
static const OffsetMenuOptionInfo canvas_x_pos_option = {
|
||||
.base_name = "Canvas X Position",
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = OFFSET_MENU_SCREENS_X_POS_INC,
|
||||
.out_action = OFFSET_MENU_SCREENS_X_POS_DEC};
|
||||
|
||||
static const OffsetMenuOptionInfo canvas_y_pos_option = {
|
||||
.base_name = "Canvas Y Position",
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = OFFSET_MENU_SCREENS_Y_POS_INC,
|
||||
.out_action = OFFSET_MENU_SCREENS_Y_POS_DEC};
|
||||
|
||||
static const OffsetMenuOptionInfo* pollable_options[] = {
|
||||
&small_screen_offset_option,
|
||||
&subscreen_distance_option,
|
||||
&canvas_x_pos_option,
|
||||
&canvas_y_pos_option,
|
||||
};
|
||||
|
||||
OffsetMenu::OffsetMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->options_indexes = new int[NUM_TOTAL_MENU_OPTIONS];
|
||||
this->initialize(font_load_success, text_font);
|
||||
this->num_enabled_options = 0;
|
||||
}
|
||||
|
||||
OffsetMenu::~OffsetMenu() {
|
||||
delete []this->options_indexes;
|
||||
}
|
||||
|
||||
void OffsetMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Offset Settings";
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void OffsetMenu::insert_data() {
|
||||
this->num_enabled_options = 0;
|
||||
for(int i = 0; i < NUM_TOTAL_MENU_OPTIONS; i++) {
|
||||
this->options_indexes[this->num_enabled_options] = i;
|
||||
this->num_enabled_options++;
|
||||
}
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void OffsetMenu::reset_output_option() {
|
||||
this->selected_index = OffsetMenuOutAction::OFFSET_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void OffsetMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = OFFSET_MENU_BACK;
|
||||
else if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->inc_out_action;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int OffsetMenu::get_num_options() {
|
||||
return this->num_enabled_options;
|
||||
}
|
||||
|
||||
std::string OffsetMenu::get_string_option(int index, int action) {
|
||||
if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->inc_str;
|
||||
if((action == DEC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->dec_str;
|
||||
return pollable_options[this->options_indexes[index]]->base_name;
|
||||
}
|
||||
|
||||
bool OffsetMenu::is_option_inc_dec(int index) {
|
||||
return pollable_options[this->options_indexes[index]]->is_inc;
|
||||
}
|
||||
|
||||
static std::string setTextOptionFloat(int option_index, float value) {
|
||||
return pollable_options[option_index]->base_name + ": " + get_float_str_decimals(value, 1);
|
||||
}
|
||||
|
||||
void OffsetMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int option_index = this->options_indexes[start + i];
|
||||
switch(pollable_options[option_index]->out_action) {
|
||||
case OFFSET_MENU_SMALL_OFFSET_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->subscreen_offset));
|
||||
break;
|
||||
case OFFSET_MENU_SMALL_SCREEN_DISTANCE_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->subscreen_attached_offset));
|
||||
break;
|
||||
case OFFSET_MENU_SCREENS_X_POS_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->total_offset_x));
|
||||
break;
|
||||
case OFFSET_MENU_SCREENS_Y_POS_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->total_offset_y));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
585
source/Menus/OptionSelectionMenu.cpp
Executable file
585
source/Menus/OptionSelectionMenu.cpp
Executable file
@@ -0,0 +1,585 @@
|
||||
#include "OptionSelectionMenu.hpp"
|
||||
|
||||
OptionSelectionMenu::OptionSelectionMenu() {
|
||||
}
|
||||
|
||||
OptionSelectionMenu::~OptionSelectionMenu() {
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++)
|
||||
delete this->labels[i];
|
||||
delete []this->labels;
|
||||
delete []this->selectable_labels;
|
||||
delete []this->future_enabled_labels;
|
||||
delete []this->loaded_enabled_labels;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::initialize(bool font_load_success, sf::Font &text_font) {
|
||||
this->class_setup();
|
||||
this->after_class_setup_connected_values();
|
||||
this->menu_rectangle.setFillColor(this->menu_color);
|
||||
this->menu_rectangle.setPosition(1, 1);
|
||||
this->labels = new TextRectangle*[this->num_elements_displayed_per_screen];
|
||||
this->selectable_labels = new bool[this->num_elements_displayed_per_screen];
|
||||
this->future_enabled_labels = new bool[this->num_elements_displayed_per_screen];
|
||||
this->loaded_enabled_labels = new bool[this->num_elements_displayed_per_screen];
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++) {
|
||||
this->labels[i] = new TextRectangle(font_load_success, text_font);
|
||||
this->labels[i]->setProportionalBox(false);
|
||||
this->labels[i]->setText(std::to_string(i));
|
||||
this->labels[i]->setShowText(true);
|
||||
this->selectable_labels[i] = true;
|
||||
this->future_enabled_labels[i] = true;
|
||||
}
|
||||
this->future_data.menu_width = 1;
|
||||
this->future_data.menu_height = 1;
|
||||
this->future_data.pos_x = 0;
|
||||
this->future_data.pos_y = 0;
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
this->last_input_processed_time = std::chrono::high_resolution_clock::now();
|
||||
this->selectable_labels[this->info_page_id] = false;
|
||||
this->selectable_labels[this->back_x_id] = this->show_back_x;
|
||||
this->selectable_labels[this->title_id] = false;
|
||||
this->future_enabled_labels[this->back_x_id] = this->show_back_x;
|
||||
this->future_enabled_labels[this->title_id] = this->show_title;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::class_setup() {
|
||||
this->num_options_per_screen = 1;
|
||||
this->min_elements_text_scaling_factor = 3;
|
||||
this->width_factor_menu = 1;
|
||||
this->width_divisor_menu = 1;
|
||||
this->base_height_factor_menu = 1;
|
||||
this->base_height_divisor_menu = 1;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Sample Menu";
|
||||
this->show_back_x = false;
|
||||
this->show_x = false;
|
||||
this->show_title = false;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::after_class_setup_connected_values() {
|
||||
this->num_title_back_x_elements = 2;
|
||||
this->num_page_elements = 3;
|
||||
this->single_option_multiplier = 3;
|
||||
this->num_elements_per_screen = single_option_multiplier * (this->num_options_per_screen + 1);
|
||||
this->num_elements_displayed_per_screen = num_title_back_x_elements + num_elements_per_screen + num_page_elements;
|
||||
this->num_vertical_slices = num_options_per_screen + 1;
|
||||
if(show_back_x || show_title)
|
||||
this->num_vertical_slices += 1;
|
||||
this->title_back_x_start_id = 0;
|
||||
this->elements_start_id = num_title_back_x_elements + title_back_x_start_id;
|
||||
this->page_elements_start_id = elements_start_id + num_elements_per_screen;
|
||||
this->back_x_id = title_back_x_start_id + 1;
|
||||
this->title_id = title_back_x_start_id;
|
||||
this->prev_page_id = page_elements_start_id;
|
||||
this->info_page_id = page_elements_start_id + 1;
|
||||
this->next_page_id = page_elements_start_id + 2;
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::can_execute_action() {
|
||||
this->last_input_processed_time = std::chrono::high_resolution_clock::now();
|
||||
auto curr_time = std::chrono::high_resolution_clock::now();
|
||||
const std::chrono::duration<double> diff = curr_time - this->last_action_time;
|
||||
if(diff.count() > this->action_timeout)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::reset_data() {
|
||||
this->last_input_processed_time = std::chrono::high_resolution_clock::now();
|
||||
this->reset_output_option();
|
||||
this->future_data.option_selected = -1;
|
||||
this->future_data.page = 0;
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::is_option_location_left(int option) {
|
||||
bool location_left = true;
|
||||
|
||||
if(option == this->next_page_id)
|
||||
location_left = false;
|
||||
else if((option >= this->elements_start_id) && (option <= (this->elements_start_id + this->num_elements_per_screen)) && (((option - this->elements_start_id) % this->single_option_multiplier) == 2))
|
||||
location_left = false;
|
||||
|
||||
return location_left;
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::is_option_element(int option) {
|
||||
return (option >= this->elements_start_id) && (option < (this->elements_start_id + this->num_elements_per_screen));
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::is_option_location_multichoice(int option) {
|
||||
bool location_left = true;
|
||||
|
||||
if((option == this->next_page_id) || (option == this->prev_page_id))
|
||||
return true;
|
||||
if(this->is_option_element(option) && (((option - this->elements_start_id) % this->single_option_multiplier) != 0))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::set_default_cursor_position() {
|
||||
this->future_data.option_selected = this->elements_start_id;
|
||||
while(!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected])){
|
||||
this->future_data.option_selected += 1;
|
||||
if(this->future_data.option_selected >= this->num_elements_displayed_per_screen)
|
||||
this->future_data.option_selected = 0;
|
||||
if(this->future_data.option_selected == this->elements_start_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::decrement_selected_option(bool is_simple) {
|
||||
if(this->future_data.option_selected < 0) {
|
||||
this->set_default_cursor_position();
|
||||
return;
|
||||
}
|
||||
bool location_left = this->is_option_location_left(this->future_data.option_selected);
|
||||
bool multichoice = this->is_option_location_multichoice(this->future_data.option_selected);
|
||||
bool was_element = this->is_option_element(this->future_data.option_selected);
|
||||
if(!is_simple) {
|
||||
if(this->future_data.option_selected == this->next_page_id)
|
||||
this->future_data.option_selected = this->prev_page_id;
|
||||
else {
|
||||
if(multichoice && location_left)
|
||||
this->future_data.option_selected -= this->single_option_multiplier - 1;
|
||||
else
|
||||
this->future_data.option_selected -= 1;
|
||||
if(was_element && !this->is_option_element(this->future_data.option_selected))
|
||||
this->future_data.option_selected = this->elements_start_id;
|
||||
}
|
||||
}
|
||||
do {
|
||||
this->future_data.option_selected -= 1;
|
||||
if(this->future_data.option_selected < 0)
|
||||
this->future_data.option_selected = this->num_elements_displayed_per_screen - 1;
|
||||
} while(!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected]));
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::increment_selected_option(bool is_simple) {
|
||||
if(this->future_data.option_selected < 0){
|
||||
this->set_default_cursor_position();
|
||||
return;
|
||||
}
|
||||
bool location_left = this->is_option_location_left(this->future_data.option_selected);
|
||||
bool success = false;
|
||||
if(!(is_simple || location_left)) {
|
||||
do {
|
||||
this->future_data.option_selected += this->single_option_multiplier;
|
||||
if(this->future_data.option_selected >= this->num_elements_displayed_per_screen) {
|
||||
break;
|
||||
}
|
||||
for(int i = 0; i < this->single_option_multiplier; i++) {
|
||||
if(this->selectable_labels[this->future_data.option_selected - i] && this->future_enabled_labels[this->future_data.option_selected - i]) {
|
||||
this->future_data.option_selected -= i;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while(!success);
|
||||
}
|
||||
if(!success) {
|
||||
if((!is_simple) && this->is_option_element(this->future_data.option_selected))
|
||||
this->future_data.option_selected += 1;
|
||||
do {
|
||||
this->future_data.option_selected += 1;
|
||||
if(this->future_data.option_selected >= this->num_elements_displayed_per_screen)
|
||||
this->future_data.option_selected = 0;
|
||||
} while(!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected]));
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::reset_output_option() {
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::set_output_option(int index, int action) {
|
||||
}
|
||||
|
||||
int OptionSelectionMenu::get_num_options() {
|
||||
return this->num_options_per_screen;
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::is_option_inc_dec(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string OptionSelectionMenu::get_string_option(int index, int action) {
|
||||
return "Sample Text";
|
||||
}
|
||||
|
||||
int OptionSelectionMenu::get_num_pages() {
|
||||
int num_pages = 1 + ((this->get_num_options() - 1) / this->num_options_per_screen);
|
||||
if(this->get_num_options() == (this->num_options_per_screen + 1))
|
||||
num_pages = 1;
|
||||
return num_pages;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::prepare_options() {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
int total_elements = this->get_num_options() - start;
|
||||
if((num_pages > 1) && (total_elements > this->num_options_per_screen))
|
||||
total_elements = this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++) {
|
||||
this->future_enabled_labels[i] = false;
|
||||
this->labels[i]->setShowText(false);
|
||||
}
|
||||
if(this->show_back_x) {
|
||||
this->future_enabled_labels[this->back_x_id] = true;
|
||||
if(this->show_x)
|
||||
this->labels[this->back_x_id]->setText("X");
|
||||
else
|
||||
this->labels[this->back_x_id]->setText("<--");
|
||||
this->labels[this->back_x_id]->setShowText(true);
|
||||
}
|
||||
if(this->show_title) {
|
||||
this->future_enabled_labels[this->title_id] = true;
|
||||
this->labels[this->title_id]->setText(this->title);
|
||||
this->labels[this->title_id]->setShowText(true);
|
||||
}
|
||||
for(int i = 0; i < total_elements; i++) {
|
||||
int label_start_index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
for(int j = 0; j < this->single_option_multiplier; j++)
|
||||
this->selectable_labels[label_start_index + j] = false;
|
||||
this->future_enabled_labels[label_start_index] = true;
|
||||
this->labels[label_start_index]->setText(this->get_string_option(start + i, DEFAULT_ACTION));
|
||||
this->labels[label_start_index]->setShowText(true);
|
||||
if(!is_option_inc_dec(start + i))
|
||||
this->selectable_labels[label_start_index] = true;
|
||||
else {
|
||||
this->labels[label_start_index + 1]->setText(this->get_string_option(start + i, DEC_ACTION));
|
||||
this->labels[label_start_index + 1]->setShowText(true);
|
||||
this->future_enabled_labels[label_start_index + 1] = true;
|
||||
this->selectable_labels[label_start_index + 1] = true;
|
||||
this->labels[label_start_index + 2]->setText(this->get_string_option(start + i, INC_ACTION));
|
||||
this->labels[label_start_index + 2]->setShowText(true);
|
||||
this->future_enabled_labels[label_start_index + 2] = true;
|
||||
this->selectable_labels[label_start_index + 2] = true;
|
||||
}
|
||||
}
|
||||
if(num_pages > 1) {
|
||||
this->future_enabled_labels[this->info_page_id] = true;
|
||||
this->labels[this->info_page_id]->setText(std::to_string(this->future_data.page + 1) + "/" + std::to_string(num_pages));
|
||||
this->labels[this->info_page_id]->setShowText(true);
|
||||
if(this->future_data.page > 0) {
|
||||
this->future_enabled_labels[this->prev_page_id] = true;
|
||||
this->labels[this->prev_page_id]->setText("<");
|
||||
this->labels[this->prev_page_id]->setShowText(true);
|
||||
}
|
||||
if(this->future_data.page < (num_pages - 1)) {
|
||||
this->future_enabled_labels[this->next_page_id] = true;
|
||||
this->labels[this->next_page_id]->setText(">");
|
||||
this->labels[this->next_page_id]->setShowText(true);
|
||||
}
|
||||
}
|
||||
if(!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected])) {
|
||||
this->future_data.option_selected = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::option_selection_handling() {
|
||||
int old_loaded_page = this->future_data.page;
|
||||
if((this->future_data.option_selected == -1) || (!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected]))) {
|
||||
this->future_data.option_selected = -1;
|
||||
return;
|
||||
}
|
||||
if(!this->can_execute_action())
|
||||
return;
|
||||
if(this->future_data.option_selected == this->back_x_id) {
|
||||
this->set_output_option(BACK_X_OUTPUT_OPTION, BAD_ACTION);
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else if(this->future_data.option_selected < (this->elements_start_id + this->num_elements_per_screen)) {
|
||||
int elem_index = this->future_data.option_selected - this->elements_start_id;
|
||||
int start = this->num_options_per_screen * this->future_data.page;
|
||||
this->set_output_option((elem_index / this->single_option_multiplier) + start, elem_index % this->single_option_multiplier);
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else if((this->future_data.option_selected == this->prev_page_id) && this->future_data.page > 0)
|
||||
this->future_data.page--;
|
||||
else if((this->future_data.option_selected == this->next_page_id) && this->future_data.page < ((this->get_num_options() - 1) / this->num_options_per_screen))
|
||||
this->future_data.page++;
|
||||
if(old_loaded_page != this->future_data.page) {
|
||||
this->prepare_options();
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::up_code(bool is_simple) {
|
||||
if(!this->can_execute_action())
|
||||
return;
|
||||
this->decrement_selected_option(is_simple);
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::down_code(bool is_simple) {
|
||||
if(!this->can_execute_action())
|
||||
return;
|
||||
this->increment_selected_option(is_simple);
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::left_code() {
|
||||
if(!this->can_execute_action())
|
||||
return;
|
||||
bool location_left = this->is_option_location_left(this->future_data.option_selected);
|
||||
bool multichoice = this->is_option_location_multichoice(this->future_data.option_selected);
|
||||
if(multichoice && location_left)
|
||||
this->option_selection_handling();
|
||||
else if(multichoice && (this->future_data.option_selected != this->next_page_id)) {
|
||||
this->future_data.option_selected -= 1;
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else if(this->selectable_labels[this->prev_page_id] && this->future_enabled_labels[this->prev_page_id]) {
|
||||
this->future_data.option_selected = this->prev_page_id;
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::right_code() {
|
||||
if(!this->can_execute_action())
|
||||
return;
|
||||
bool location_left = this->is_option_location_left(this->future_data.option_selected);
|
||||
bool multichoice = this->is_option_location_multichoice(this->future_data.option_selected);
|
||||
if(multichoice && (!location_left))
|
||||
this->option_selection_handling();
|
||||
else if(multichoice && (this->future_data.option_selected != this->prev_page_id)) {
|
||||
this->future_data.option_selected += 1;
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else if(this->selectable_labels[this->next_page_id] && this->future_enabled_labels[this->next_page_id]) {
|
||||
this->future_data.option_selected = this->next_page_id;
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
bool OptionSelectionMenu::poll(SFEvent &event_data) {
|
||||
bool consumed = true;
|
||||
switch (event_data.type) {
|
||||
case sf::Event::TextEntered:
|
||||
switch (event_data.unicode) {
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case sf::Event::KeyPressed:
|
||||
switch (event_data.code) {
|
||||
case sf::Keyboard::Up:
|
||||
this->up_code(false);
|
||||
break;
|
||||
case sf::Keyboard::Down:
|
||||
this->down_code(false);
|
||||
break;
|
||||
case sf::Keyboard::PageUp:
|
||||
this->up_code(true);
|
||||
break;
|
||||
case sf::Keyboard::PageDown:
|
||||
this->down_code(true);
|
||||
break;
|
||||
case sf::Keyboard::Left:
|
||||
this->left_code();
|
||||
break;
|
||||
case sf::Keyboard::Right:
|
||||
this->right_code();
|
||||
break;
|
||||
case sf::Keyboard::Enter:
|
||||
this->option_selection_handling();
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case sf::Event::MouseMoved:
|
||||
this->future_data.option_selected = -1;
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++) {
|
||||
if(!(this->selectable_labels[i] && this->future_enabled_labels[i]))
|
||||
continue;
|
||||
if(this->labels[i]->isCoordInRectangle(event_data.mouse_x, event_data.mouse_y)) {
|
||||
this->future_data.option_selected = i;
|
||||
this->last_input_processed_time = std::chrono::high_resolution_clock::now();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case sf::Event::MouseButtonPressed:
|
||||
this->future_data.option_selected = -1;
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++) {
|
||||
if(!(this->selectable_labels[i] && this->future_enabled_labels[i]))
|
||||
continue;
|
||||
if(this->labels[i]->isCoordInRectangle(event_data.mouse_x, event_data.mouse_y)) {
|
||||
this->future_data.option_selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(this->future_data.option_selected == -1)
|
||||
break;
|
||||
if(event_data.mouse_button == sf::Mouse::Left)
|
||||
this->option_selection_handling();
|
||||
break;
|
||||
case sf::Event::JoystickButtonPressed:
|
||||
switch(get_joystick_action(event_data.joystickId, event_data.joy_button)) {
|
||||
case JOY_ACTION_CONFIRM:
|
||||
this->option_selection_handling();
|
||||
break;
|
||||
case JOY_ACTION_NEGATE:
|
||||
this->option_selection_handling();
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case sf::Event::JoystickMoved:
|
||||
switch(get_joystick_direction(event_data.joystickId, event_data.axis, event_data.position)) {
|
||||
case JOY_DIR_UP:
|
||||
this->up_code(false);
|
||||
break;
|
||||
case JOY_DIR_DOWN:
|
||||
this->down_code(false);
|
||||
break;
|
||||
case JOY_DIR_LEFT:
|
||||
this->left_code();
|
||||
break;
|
||||
case JOY_DIR_RIGHT:
|
||||
this->right_code();
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::draw(float scaling_factor, sf::RenderTarget &window) {
|
||||
const sf::Vector2f rect_size = this->menu_rectangle.getSize();
|
||||
if((this->loaded_data.menu_width != rect_size.x) || (this->loaded_data.menu_height != rect_size.y)) {
|
||||
this->menu_rectangle.setSize(sf::Vector2f(this->loaded_data.menu_width, this->loaded_data.menu_height));
|
||||
}
|
||||
this->menu_rectangle.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y);
|
||||
window.draw(this->menu_rectangle);
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++) {
|
||||
if(this->loaded_enabled_labels[i])
|
||||
this->labels[i]->draw(window);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::prepare_text_slices(int x_multiplier, int x_divisor, int y_multiplier, int y_divisor, int index, float text_scaling_factor, bool center) {
|
||||
this->labels[index]->setTextFactor(text_scaling_factor);
|
||||
int x_base_pos = (this->future_data.menu_width * x_multiplier) / x_divisor;
|
||||
int y_base_pos = (this->future_data.menu_height * y_multiplier) / y_divisor;
|
||||
int x_size = ((this->future_data.menu_width * (x_multiplier + 1)) / x_divisor) - x_base_pos;
|
||||
int y_size = ((this->future_data.menu_height * (y_multiplier + 1)) / y_divisor) - y_base_pos;
|
||||
if(center)
|
||||
x_size = ((this->future_data.menu_width * (x_divisor - x_multiplier)) / x_divisor) - x_base_pos;
|
||||
this->labels[index]->setSize(x_size, y_size);
|
||||
this->labels[index]->setPosition(this->future_data.pos_x + x_base_pos, this->future_data.pos_y + y_base_pos);
|
||||
if(index == this->future_data.option_selected) {
|
||||
if((index == this->back_x_id) && this->show_x)
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_ERROR);
|
||||
else
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_SELECTED);
|
||||
}
|
||||
else {
|
||||
if((index == this->back_x_id) && this->show_x)
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_OPAQUE_ERROR);
|
||||
else if(!this->selectable_labels[index])
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_TITLE);
|
||||
else
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_NORMAL);
|
||||
}
|
||||
this->labels[index]->prepareRenderText();
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::base_prepare(float menu_scaling_factor, int view_size_x, int view_size_y) {
|
||||
int num_elements = 0;
|
||||
bool has_top = this->future_enabled_labels[this->back_x_id] || this->future_enabled_labels[this->title_id];
|
||||
if(has_top)
|
||||
num_elements += 1;
|
||||
for(int i = 0; i < (this->num_options_per_screen + 1); i++)
|
||||
if(this->future_enabled_labels[(i * this->single_option_multiplier) + this->elements_start_id])
|
||||
num_elements++;
|
||||
bool has_bottom = false;
|
||||
for(int i = 0; i < this->num_page_elements; i++)
|
||||
if(this->future_enabled_labels[i + this->page_elements_start_id])
|
||||
has_bottom = true;
|
||||
if(has_bottom)
|
||||
num_elements += 1;
|
||||
const float base_height = (this->num_vertical_slices * BASE_PIXEL_FONT_HEIGHT * 11) / 9;
|
||||
int max_width = (view_size_x * 9) / 10;
|
||||
int max_height = (view_size_y * 9) / 10;
|
||||
float max_width_corresponding_height = (max_width * this->width_divisor_menu * this->max_width_slack) / this->width_factor_menu;
|
||||
float max_scaling_factor = max_height / base_height;
|
||||
if(max_width_corresponding_height < max_height)
|
||||
max_scaling_factor = max_width_corresponding_height / base_height;
|
||||
float final_menu_scaling_factor = (menu_scaling_factor * this->base_height_factor_menu) / this->base_height_divisor_menu;
|
||||
if(menu_scaling_factor > max_scaling_factor)
|
||||
menu_scaling_factor = max_scaling_factor;
|
||||
if(final_menu_scaling_factor > max_scaling_factor)
|
||||
final_menu_scaling_factor = max_scaling_factor;
|
||||
if(menu_scaling_factor < this->min_text_size)
|
||||
menu_scaling_factor = this->min_text_size;
|
||||
if(final_menu_scaling_factor < this->min_text_size)
|
||||
final_menu_scaling_factor = this->min_text_size;
|
||||
int num_elements_text_scaling_factor = num_elements;
|
||||
if(num_elements_text_scaling_factor < this->min_elements_text_scaling_factor)
|
||||
num_elements_text_scaling_factor = this->min_elements_text_scaling_factor;
|
||||
float text_scaling_factor = (menu_scaling_factor * this->num_vertical_slices) / num_elements_text_scaling_factor;
|
||||
this->future_data.menu_height = base_height * final_menu_scaling_factor;
|
||||
this->future_data.menu_width = (this->future_data.menu_height * this->width_factor_menu) / this->width_divisor_menu;
|
||||
if(this->future_data.menu_width > max_width)
|
||||
this->future_data.menu_width = max_width;
|
||||
this->future_data.pos_x = (view_size_x - this->future_data.menu_width) / 2;
|
||||
this->future_data.pos_y = (view_size_y - this->future_data.menu_height) / 2;
|
||||
int slice_y_size = this->future_data.menu_height / num_elements;
|
||||
int slice_x_size = this->future_data.menu_width / this->num_page_elements;
|
||||
int num_rendered_y = 0;
|
||||
if(this->future_enabled_labels[this->back_x_id]) {
|
||||
int top_divisor = 1;
|
||||
if(this->future_enabled_labels[this->title_id])
|
||||
top_divisor = 6;
|
||||
this->prepare_text_slices(0, top_divisor, num_rendered_y, num_elements, this->back_x_id, text_scaling_factor);
|
||||
}
|
||||
if(this->future_enabled_labels[this->title_id]) {
|
||||
this->prepare_text_slices(0, 1, num_rendered_y, num_elements, this->title_id, text_scaling_factor);
|
||||
}
|
||||
if(has_top)
|
||||
++num_rendered_y;
|
||||
for(int i = 0; i < (this->num_options_per_screen + 1); i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(this->future_enabled_labels[index]) {
|
||||
int elem_divisor = 1;
|
||||
if(this->future_enabled_labels[index + 1] || this->future_enabled_labels[index + 2])
|
||||
elem_divisor = 6;
|
||||
this->prepare_text_slices(0, 1, num_rendered_y, num_elements, index, text_scaling_factor);
|
||||
if(this->future_enabled_labels[index + 1])
|
||||
this->prepare_text_slices(0, elem_divisor, num_rendered_y, num_elements, index + 1, text_scaling_factor);
|
||||
if(this->future_enabled_labels[index + 2])
|
||||
this->prepare_text_slices(elem_divisor - 1, elem_divisor, num_rendered_y, num_elements, index + 2, text_scaling_factor);
|
||||
++num_rendered_y;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < this->num_page_elements; i++) {
|
||||
int index = i + this->page_elements_start_id;
|
||||
if(this->future_enabled_labels[index]){
|
||||
this->prepare_text_slices(i, this->num_page_elements, num_rendered_y, num_elements, index, text_scaling_factor);
|
||||
}
|
||||
}
|
||||
if(has_bottom)
|
||||
++num_rendered_y;
|
||||
this->loaded_data = this->future_data;
|
||||
for(int i = 0; i < this->num_elements_displayed_per_screen; i++)
|
||||
this->loaded_enabled_labels[i] = this->future_enabled_labels[i];
|
||||
}
|
||||
70
source/Menus/PARMenu.cpp
Executable file
70
source/Menus/PARMenu.cpp
Executable file
@@ -0,0 +1,70 @@
|
||||
#include "PARMenu.hpp"
|
||||
|
||||
PARMenu::PARMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->initialize(font_load_success, text_font);
|
||||
}
|
||||
|
||||
PARMenu::~PARMenu() {
|
||||
}
|
||||
|
||||
void PARMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = this->base_name;
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void PARMenu::setup_title(std::string added_name) {
|
||||
this->title = added_name + (added_name != "" ? " " : "") + this->base_name;
|
||||
}
|
||||
|
||||
void PARMenu::insert_data(std::vector<const PARData*>* possible_pars) {
|
||||
this->possible_pars = possible_pars;
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void PARMenu::reset_output_option() {
|
||||
this->selected_index = PAR_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void PARMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = PAR_MENU_BACK;
|
||||
else
|
||||
this->selected_index = index;
|
||||
}
|
||||
|
||||
int PARMenu::get_num_options() {
|
||||
return (*this->possible_pars).size();
|
||||
}
|
||||
|
||||
std::string PARMenu::get_string_option(int index, int action) {
|
||||
return (*this->possible_pars)[index]->name;
|
||||
}
|
||||
|
||||
void PARMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, int current_par) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int par_index = start + i;
|
||||
if(par_index == current_par)
|
||||
this->labels[index]->setText("<" + (*this->possible_pars)[par_index]->name + ">");
|
||||
else
|
||||
this->labels[index]->setText((*this->possible_pars)[par_index]->name);
|
||||
}
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
126
source/Menus/RotationMenu.cpp
Executable file
126
source/Menus/RotationMenu.cpp
Executable file
@@ -0,0 +1,126 @@
|
||||
#include "RotationMenu.hpp"
|
||||
|
||||
#define NUM_TOTAL_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
|
||||
|
||||
struct RotationMenuOptionInfo {
|
||||
const std::string base_name;
|
||||
const bool is_inc;
|
||||
const std::string dec_str;
|
||||
const std::string inc_str;
|
||||
const RotationMenuOutAction inc_out_action;
|
||||
const RotationMenuOutAction out_action;
|
||||
};
|
||||
|
||||
static const RotationMenuOptionInfo top_rotation_option = {
|
||||
.base_name = "Top Screen",
|
||||
.is_inc = true, .dec_str = "Left", .inc_str = "Right", .inc_out_action = ROTATION_MENU_TOP_ROTATION_INC,
|
||||
.out_action = ROTATION_MENU_TOP_ROTATION_DEC};
|
||||
|
||||
static const RotationMenuOptionInfo bottom_rotation_option = {
|
||||
.base_name = "Bottom Screen",
|
||||
.is_inc = true, .dec_str = "Left", .inc_str = "Right", .inc_out_action = ROTATION_MENU_BOTTOM_ROTATION_INC,
|
||||
.out_action = ROTATION_MENU_BOTTOM_ROTATION_DEC};
|
||||
|
||||
static const RotationMenuOptionInfo both_rotation_option = {
|
||||
.base_name = "Both Screens",
|
||||
.is_inc = true, .dec_str = "Left", .inc_str = "Right", .inc_out_action = ROTATION_MENU_BOTH_ROTATION_INC,
|
||||
.out_action = ROTATION_MENU_BOTH_ROTATION_DEC};
|
||||
|
||||
static const RotationMenuOptionInfo* pollable_options[] = {
|
||||
&top_rotation_option,
|
||||
&bottom_rotation_option,
|
||||
&both_rotation_option,
|
||||
};
|
||||
|
||||
RotationMenu::RotationMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->options_indexes = new int[NUM_TOTAL_MENU_OPTIONS];
|
||||
this->initialize(font_load_success, text_font);
|
||||
this->num_enabled_options = 0;
|
||||
}
|
||||
|
||||
RotationMenu::~RotationMenu() {
|
||||
delete []this->options_indexes;
|
||||
}
|
||||
|
||||
void RotationMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Rotation Settings";
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void RotationMenu::insert_data() {
|
||||
this->num_enabled_options = 0;
|
||||
for(int i = 0; i < NUM_TOTAL_MENU_OPTIONS; i++) {
|
||||
this->options_indexes[this->num_enabled_options] = i;
|
||||
this->num_enabled_options++;
|
||||
}
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void RotationMenu::reset_output_option() {
|
||||
this->selected_index = RotationMenuOutAction::ROTATION_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void RotationMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = ROTATION_MENU_BACK;
|
||||
else if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->inc_out_action;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int RotationMenu::get_num_options() {
|
||||
return this->num_enabled_options;
|
||||
}
|
||||
|
||||
std::string RotationMenu::get_string_option(int index, int action) {
|
||||
if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->inc_str;
|
||||
if((action == DEC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->dec_str;
|
||||
return pollable_options[this->options_indexes[index]]->base_name;
|
||||
}
|
||||
|
||||
bool RotationMenu::is_option_inc_dec(int index) {
|
||||
return pollable_options[this->options_indexes[index]]->is_inc;
|
||||
}
|
||||
|
||||
static std::string setTextOptionInt(int option_index, int value) {
|
||||
return pollable_options[option_index]->base_name + ": " + std::to_string(value);
|
||||
}
|
||||
|
||||
void RotationMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int option_index = this->options_indexes[start + i];
|
||||
switch(pollable_options[option_index]->out_action) {
|
||||
case ROTATION_MENU_TOP_ROTATION_DEC:
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->top_rotation));
|
||||
break;
|
||||
case ROTATION_MENU_BOTTOM_ROTATION_DEC:
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->bot_rotation));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
321
source/Menus/VideoMenu.cpp
Executable file
321
source/Menus/VideoMenu.cpp
Executable file
@@ -0,0 +1,321 @@
|
||||
#include "VideoMenu.hpp"
|
||||
|
||||
#define NUM_TOTAL_VIDEO_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
|
||||
|
||||
struct VideoMenuOptionInfo {
|
||||
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 bool is_inc;
|
||||
const std::string dec_str;
|
||||
const std::string inc_str;
|
||||
const VideoMenuOutAction inc_out_action;
|
||||
const VideoMenuOutAction out_action;
|
||||
};
|
||||
|
||||
static const VideoMenuOptionInfo 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,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_VSYNC};
|
||||
|
||||
static const VideoMenuOptionInfo 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,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_ASYNC};
|
||||
|
||||
static const VideoMenuOptionInfo 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,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_BLUR};
|
||||
|
||||
static const VideoMenuOptionInfo 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,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_PADDING};
|
||||
|
||||
static const VideoMenuOptionInfo crop_option = {
|
||||
.base_name = "Crop Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_CROPPING};
|
||||
|
||||
static const VideoMenuOptionInfo top_par_option = {
|
||||
.base_name = "Top Screen PAR", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_TOP_PAR};
|
||||
|
||||
static const VideoMenuOptionInfo bot_par_option = {
|
||||
.base_name = "Bottom Screen PAR", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_BOT_PAR};
|
||||
|
||||
static const VideoMenuOptionInfo one_par_option = {
|
||||
.base_name = "Screen PAR", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = false, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_ONE_PAR};
|
||||
|
||||
static const VideoMenuOptionInfo bottom_screen_pos_option = {
|
||||
.base_name = "Screens Relative Positions", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_BOTTOM_SCREEN_POS};
|
||||
|
||||
static const VideoMenuOptionInfo small_screen_offset_option = {
|
||||
.base_name = "Screen Offset", .false_name = "",
|
||||
.active_fullscreen = false, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = VIDEO_MENU_SMALL_SCREEN_OFFSET_INC,
|
||||
.out_action = VIDEO_MENU_SMALL_SCREEN_OFFSET_DEC};
|
||||
|
||||
static const VideoMenuOptionInfo offset_settings_option = {
|
||||
.base_name = "Offset Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = false,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_OFFSET_SETTINGS};
|
||||
|
||||
static const VideoMenuOptionInfo window_scaling_option = {
|
||||
.base_name = "Scaling Factor", .false_name = "",
|
||||
.active_fullscreen = false, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = VIDEO_MENU_WINDOW_SCALING_INC,
|
||||
.out_action = VIDEO_MENU_WINDOW_SCALING_DEC};
|
||||
|
||||
static const VideoMenuOptionInfo fullscreen_scaling_option = {
|
||||
.base_name = "Screens Ratio", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = false,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = true, .dec_str = "+ Top", .inc_str = "+ Bot.", .inc_out_action = VIDEO_MENU_FULLSCREEN_SCALING_BOTTOM,
|
||||
.out_action = VIDEO_MENU_FULLSCREEN_SCALING_TOP};
|
||||
|
||||
static const VideoMenuOptionInfo bfi_settings_option = {
|
||||
.base_name = "BFI Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_BFI_SETTINGS};
|
||||
|
||||
static const VideoMenuOptionInfo menu_scaling_option = {
|
||||
.base_name = "Menu Scaling", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = true, .dec_str = "-", .inc_str = "+", .inc_out_action = VIDEO_MENU_MENU_SCALING_INC,
|
||||
.out_action = VIDEO_MENU_MENU_SCALING_DEC};
|
||||
|
||||
static const VideoMenuOptionInfo resolution_settings_option = {
|
||||
.base_name = "Resolution Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = false,
|
||||
.active_joint_screen = true, .active_top_screen = true, .active_bottom_screen = true,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_RESOLUTION_SETTINGS};
|
||||
|
||||
static const VideoMenuOptionInfo rotation_settings_option = {
|
||||
.base_name = "Rotation Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = true, .active_top_screen = false, .active_bottom_screen = false,
|
||||
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = VIDEO_MENU_NO_ACTION,
|
||||
.out_action = VIDEO_MENU_ROTATION_SETTINGS};
|
||||
|
||||
static const VideoMenuOptionInfo top_one_rotation_option = {
|
||||
.base_name = "Screen Rotation", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = false, .active_top_screen = true, .active_bottom_screen = false,
|
||||
.is_inc = true, .dec_str = "Left", .inc_str = "Right", .inc_out_action = VIDEO_MENU_TOP_ROTATION_INC,
|
||||
.out_action = VIDEO_MENU_TOP_ROTATION_DEC};
|
||||
|
||||
static const VideoMenuOptionInfo bottom_one_rotation_option = {
|
||||
.base_name = "Screen Rotation", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
.active_joint_screen = false, .active_top_screen = false, .active_bottom_screen = true,
|
||||
.is_inc = true, .dec_str = "Left", .inc_str = "Right", .inc_out_action = VIDEO_MENU_BOTTOM_ROTATION_INC,
|
||||
.out_action = VIDEO_MENU_BOTTOM_ROTATION_DEC};
|
||||
|
||||
static const VideoMenuOptionInfo* pollable_options[] = {
|
||||
&crop_option,
|
||||
&window_scaling_option,
|
||||
&fullscreen_scaling_option,
|
||||
&menu_scaling_option,
|
||||
&bottom_screen_pos_option,
|
||||
&vsync_option,
|
||||
&async_option,
|
||||
&blur_option,
|
||||
&small_screen_offset_option,
|
||||
&offset_settings_option,
|
||||
&rotation_settings_option,
|
||||
&top_one_rotation_option,
|
||||
&bottom_one_rotation_option,
|
||||
&top_par_option,
|
||||
&bot_par_option,
|
||||
&one_par_option,
|
||||
&resolution_settings_option,
|
||||
&padding_option,
|
||||
&bfi_settings_option,
|
||||
};
|
||||
|
||||
VideoMenu::VideoMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
this->options_indexes = new int[NUM_TOTAL_VIDEO_MENU_OPTIONS];
|
||||
this->initialize(font_load_success, text_font);
|
||||
this->num_enabled_options = 0;
|
||||
}
|
||||
|
||||
VideoMenu::~VideoMenu() {
|
||||
delete []this->options_indexes;
|
||||
}
|
||||
|
||||
void VideoMenu::class_setup() {
|
||||
this->num_options_per_screen = 5;
|
||||
this->min_elements_text_scaling_factor = num_options_per_screen + 2;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
this->base_height_factor_menu = 12;
|
||||
this->base_height_divisor_menu = 6;
|
||||
this->min_text_size = 0.3;
|
||||
this->max_width_slack = 1.1;
|
||||
this->menu_color = sf::Color(30, 30, 60, 192);
|
||||
this->title = "Video Settings";
|
||||
this->show_back_x = true;
|
||||
this->show_x = false;
|
||||
this->show_title = true;
|
||||
}
|
||||
|
||||
void VideoMenu::insert_data(ScreenType s_type, bool is_fullscreen) {
|
||||
this->num_enabled_options = 0;
|
||||
for(int i = 0; i < NUM_TOTAL_VIDEO_MENU_OPTIONS; 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++;
|
||||
}
|
||||
}
|
||||
this->prepare_options();
|
||||
}
|
||||
|
||||
void VideoMenu::reset_output_option() {
|
||||
this->selected_index = VideoMenuOutAction::VIDEO_MENU_NO_ACTION;
|
||||
}
|
||||
|
||||
void VideoMenu::set_output_option(int index, int action) {
|
||||
if(index == BACK_X_OUTPUT_OPTION)
|
||||
this->selected_index = VIDEO_MENU_BACK;
|
||||
else if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->inc_out_action;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int VideoMenu::get_num_options() {
|
||||
return this->num_enabled_options;
|
||||
}
|
||||
|
||||
std::string VideoMenu::get_string_option(int index, int action) {
|
||||
if((action == INC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->inc_str;
|
||||
if((action == DEC_ACTION) && this->is_option_inc_dec(index))
|
||||
return pollable_options[this->options_indexes[index]]->dec_str;
|
||||
return pollable_options[this->options_indexes[index]]->base_name;
|
||||
}
|
||||
|
||||
bool VideoMenu::is_option_inc_dec(int index) {
|
||||
return pollable_options[this->options_indexes[index]]->is_inc;
|
||||
}
|
||||
|
||||
static std::string setTextOptionBool(int option_index, bool value) {
|
||||
if(value)
|
||||
return pollable_options[option_index]->base_name;
|
||||
return pollable_options[option_index]->false_name;
|
||||
}
|
||||
|
||||
static std::string setTextOptionFloat(int option_index, float value) {
|
||||
return pollable_options[option_index]->base_name + ": " + get_float_str_decimals(value, 1);
|
||||
}
|
||||
|
||||
static std::string setTextOptionInt(int option_index, int value) {
|
||||
return pollable_options[option_index]->base_name + ": " + std::to_string(value);
|
||||
}
|
||||
|
||||
static std::string setTextOptionDualPercentage(int option_index, int value_1, int value_2) {
|
||||
int sum = value_1 + value_2;
|
||||
value_1 = ((value_1 * 100) + (sum / 2)) / sum;
|
||||
value_2 = ((value_2 * 100) + (sum / 2)) / sum;
|
||||
value_1 += 100 - (value_1 + value_2);
|
||||
return pollable_options[option_index]->base_name + ": " + std::to_string(value_1) + " - " + std::to_string(value_2);
|
||||
}
|
||||
|
||||
void VideoMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info) {
|
||||
int num_pages = this->get_num_pages();
|
||||
if(this->future_data.page >= num_pages)
|
||||
this->future_data.page = num_pages - 1;
|
||||
int start = this->future_data.page * this->num_options_per_screen;
|
||||
for(int i = 0; i < this->num_options_per_screen + 1; i++) {
|
||||
int index = (i * this->single_option_multiplier) + this->elements_start_id;
|
||||
if(!this->future_enabled_labels[index])
|
||||
continue;
|
||||
int option_index = this->options_indexes[start + i];
|
||||
switch(pollable_options[option_index]->out_action) {
|
||||
case VIDEO_MENU_VSYNC:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->v_sync_enabled));
|
||||
break;
|
||||
case VIDEO_MENU_ASYNC:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->async));
|
||||
break;
|
||||
case VIDEO_MENU_BLUR:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->is_blurred));
|
||||
break;
|
||||
case VIDEO_MENU_PADDING:
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->rounded_corners_fix));
|
||||
break;
|
||||
case VIDEO_MENU_WINDOW_SCALING_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->scaling));
|
||||
break;
|
||||
case VIDEO_MENU_MENU_SCALING_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->menu_scaling_factor));
|
||||
break;
|
||||
case VIDEO_MENU_FULLSCREEN_SCALING_TOP:
|
||||
this->labels[index]->setText(setTextOptionDualPercentage(option_index, info->top_scaling, info->bot_scaling));
|
||||
break;
|
||||
case VIDEO_MENU_SMALL_SCREEN_OFFSET_DEC:
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->subscreen_offset));
|
||||
break;
|
||||
case VIDEO_MENU_TOP_ROTATION_DEC:
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->top_rotation));
|
||||
break;
|
||||
case VIDEO_MENU_BOTTOM_ROTATION_DEC:
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->bot_rotation));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->base_prepare(menu_scaling_factor, view_size_x, view_size_y);
|
||||
}
|
||||
Reference in New Issue
Block a user