mirror of
https://github.com/Lorenzooone/cc3dsfs.git
synced 2026-09-12 18:45:20 -05:00
Add title and back or X option
This commit is contained in:
@@ -41,6 +41,7 @@ enum MainMenuOutAction{
|
||||
MAIN_MENU_EXTRA_SETTINGS,
|
||||
MAIN_MENU_TOP_ROTATION,
|
||||
MAIN_MENU_BOTTOM_ROTATION,
|
||||
MAIN_MENU_SHUTDOWN,
|
||||
};
|
||||
|
||||
class MainMenu : public OptionSelectionMenu {
|
||||
|
||||
@@ -16,30 +16,32 @@ public:
|
||||
void reset_data();
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> last_input_processed_time;
|
||||
protected:
|
||||
int num_elements_per_screen = 1;
|
||||
int num_page_elements = 3;
|
||||
int num_elements_displayed_per_screen = num_elements_per_screen + num_page_elements;
|
||||
int num_vertical_slices = (num_elements_displayed_per_screen - (num_page_elements - 1));
|
||||
int num_elements_start_id = 0;
|
||||
int num_page_elements_start_id = num_elements_per_screen + num_elements_start_id;
|
||||
int prev_page_id = num_page_elements_start_id;
|
||||
int info_page_id = num_page_elements_start_id + 1;
|
||||
int next_page_id = num_page_elements_start_id + 2;
|
||||
int min_elements_text_scaling_factor = 3;
|
||||
int width_factor_menu = 1;
|
||||
int width_divisor_menu = 1;
|
||||
int base_height_factor_menu = 1;
|
||||
int base_height_divisor_menu = 1;
|
||||
float min_text_size = 0.3;
|
||||
float max_width_slack = 1.1;
|
||||
int num_elements_per_screen;
|
||||
int elements_start_id;
|
||||
int min_elements_text_scaling_factor;
|
||||
int width_factor_menu;
|
||||
int width_divisor_menu;
|
||||
int base_height_factor_menu;
|
||||
int base_height_divisor_menu;
|
||||
float min_text_size;
|
||||
float max_width_slack;
|
||||
sf::Color menu_color;
|
||||
std::string title;
|
||||
bool show_back_x;
|
||||
bool show_x;
|
||||
bool show_title;
|
||||
|
||||
virtual void reset_output_option();
|
||||
virtual void set_output_option(int index);
|
||||
virtual int get_num_options();
|
||||
virtual std::string get_string_option(int index);
|
||||
virtual void class_setup();
|
||||
|
||||
int get_num_pages();
|
||||
void initialize(bool font_load_success, sf::Font &text_font);
|
||||
void prepare_options();
|
||||
void base_prepare(float menu_scaling_factor, int view_size_x, int view_size_y);
|
||||
|
||||
struct MenuData {
|
||||
int page = 0;
|
||||
int option_selected = -1;
|
||||
@@ -52,6 +54,19 @@ protected:
|
||||
TextRectangle **labels;
|
||||
bool *future_enabled_labels;
|
||||
private:
|
||||
int num_title_back_x_elements;
|
||||
int num_page_elements;
|
||||
int num_elements_displayed_per_screen;
|
||||
int num_vertical_slices;
|
||||
int title_back_x_start_id;
|
||||
int page_elements_start_id;
|
||||
int back_x_id;
|
||||
int title_id;
|
||||
int title_center_id;
|
||||
int prev_page_id;
|
||||
int info_page_id;
|
||||
int next_page_id;
|
||||
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> last_action_time;
|
||||
const float action_timeout = 0.1;
|
||||
int loaded_page = 0;
|
||||
@@ -59,8 +74,10 @@ private:
|
||||
bool *selectable_labels;
|
||||
bool *loaded_enabled_labels;
|
||||
MenuData loaded_data;
|
||||
sf::RectangleShape menu_rectangle = sf::RectangleShape(sf::Vector2f(1, 1));
|
||||
|
||||
void prepare_text_slices(int x_multiplier, int x_divisor, int y_multiplier, int y_divisor, int index, float text_scaling_factor);
|
||||
void after_class_setup_connected_values();
|
||||
void prepare_text_slices(int x_multiplier, int x_divisor, int y_multiplier, int y_divisor, int index, float text_scaling_factor, bool center = false);
|
||||
bool can_execute_action();
|
||||
void up_code();
|
||||
void down_code();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#define BASE_PIXEL_FONT_HEIGHT 24
|
||||
|
||||
enum TextKind {TEXT_KIND_NORMAL, TEXT_KIND_SELECTED, TEXT_KIND_SUCCESS, TEXT_KIND_WARNING, TEXT_KIND_ERROR};
|
||||
enum TextKind {TEXT_KIND_NORMAL, TEXT_KIND_SELECTED, TEXT_KIND_SUCCESS, TEXT_KIND_WARNING, TEXT_KIND_ERROR, TEXT_KIND_OPAQUE_ERROR, TEXT_KIND_TITLE};
|
||||
|
||||
class TextRectangle {
|
||||
public:
|
||||
@@ -34,11 +34,7 @@ private:
|
||||
bool is_done_showing_text;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> clock_time_start;
|
||||
int time_phase;
|
||||
sf::Color *base_bg_color;
|
||||
sf::Color *selected_bg_color;
|
||||
sf::Color *success_bg_color;
|
||||
sf::Color *warning_bg_color;
|
||||
sf::Color *error_bg_color;
|
||||
sf::Color curr_color;
|
||||
const float base_time_slide_factor = 0.5;
|
||||
const float base_pixel_slide_factor = 2.0;
|
||||
|
||||
|
||||
@@ -9,14 +9,6 @@ ConnectionMenu::~ConnectionMenu() {
|
||||
|
||||
void ConnectionMenu::class_setup() {
|
||||
this->num_elements_per_screen = 4;
|
||||
this->num_page_elements = 3;
|
||||
this->num_elements_displayed_per_screen = num_elements_per_screen + num_page_elements;
|
||||
this->num_vertical_slices = (num_elements_displayed_per_screen - (num_page_elements - 1));
|
||||
this->num_elements_start_id = 0;
|
||||
this->num_page_elements_start_id = num_elements_per_screen + num_elements_start_id;
|
||||
this->prev_page_id = num_page_elements_start_id;
|
||||
this->info_page_id = num_page_elements_start_id + 1;
|
||||
this->next_page_id = num_page_elements_start_id + 2;
|
||||
this->min_elements_text_scaling_factor = num_elements_per_screen;
|
||||
this->width_factor_menu = 16;
|
||||
this->width_divisor_menu = 9;
|
||||
@@ -24,6 +16,11 @@ void ConnectionMenu::class_setup() {
|
||||
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) {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#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;
|
||||
@@ -73,18 +75,18 @@ static const MainMenuOptionInfo padding_option = {
|
||||
.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,
|
||||
.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 crop_option = {
|
||||
.base_name = "Crop Settings", .false_name = "",
|
||||
.active_fullscreen = true, .active_windowed_screen = true,
|
||||
@@ -263,8 +265,8 @@ static const MainMenuOptionInfo* pollable_options[] = {
|
||||
&extra_settings_option,
|
||||
&status_option,
|
||||
&licenses_option,
|
||||
&close_option,
|
||||
&quit_option
|
||||
&quit_option,
|
||||
&shutdown_option
|
||||
};
|
||||
|
||||
MainMenu::MainMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
|
||||
@@ -279,21 +281,18 @@ MainMenu::~MainMenu() {
|
||||
|
||||
void MainMenu::class_setup() {
|
||||
this->num_elements_per_screen = 5;
|
||||
this->num_page_elements = 3;
|
||||
this->num_elements_displayed_per_screen = num_elements_per_screen + num_page_elements;
|
||||
this->num_vertical_slices = (num_elements_displayed_per_screen - (num_page_elements - 1));
|
||||
this->num_elements_start_id = 0;
|
||||
this->num_page_elements_start_id = num_elements_per_screen + num_elements_start_id;
|
||||
this->prev_page_id = num_page_elements_start_id;
|
||||
this->info_page_id = num_page_elements_start_id + 1;
|
||||
this->next_page_id = num_page_elements_start_id + 2;
|
||||
this->min_elements_text_scaling_factor = this->num_vertical_slices;
|
||||
this->min_elements_text_scaling_factor = num_elements_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) {
|
||||
@@ -323,7 +322,10 @@ void MainMenu::reset_output_option() {
|
||||
}
|
||||
|
||||
void MainMenu::set_output_option(int index) {
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
if(index == -1)
|
||||
this->selected_index = MAIN_MENU_CLOSE_MENU;
|
||||
else
|
||||
this->selected_index = pollable_options[this->options_indexes[index]]->out_action;
|
||||
}
|
||||
|
||||
int MainMenu::get_num_options() {
|
||||
@@ -357,44 +359,45 @@ static std::string setTextOptionDualPercentage(int option_index, int value_1, in
|
||||
}
|
||||
|
||||
void MainMenu::prepare(float menu_scaling_factor, int view_size_x, int view_size_y, ScreenInfo *info, bool connected) {
|
||||
int num_pages = 1 + ((this->get_num_options() - 1) / this->num_elements_per_screen);
|
||||
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_elements_per_screen;
|
||||
for(int i = 0; i < this->num_elements_per_screen; i++) {
|
||||
if(!this->future_enabled_labels[i])
|
||||
int index = i + 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[i]->setText(setTextOptionBool(option_index, connected));
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, connected));
|
||||
break;
|
||||
case MAIN_MENU_VSYNC:
|
||||
this->labels[i]->setText(setTextOptionBool(option_index, info->v_sync_enabled));
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->v_sync_enabled));
|
||||
break;
|
||||
case MAIN_MENU_ASYNC:
|
||||
this->labels[i]->setText(setTextOptionBool(option_index, info->async));
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->async));
|
||||
break;
|
||||
case MAIN_MENU_BLUR:
|
||||
this->labels[i]->setText(setTextOptionBool(option_index, info->is_blurred));
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->is_blurred));
|
||||
break;
|
||||
case MAIN_MENU_PADDING:
|
||||
this->labels[i]->setText(setTextOptionBool(option_index, info->rounded_corners_fix));
|
||||
this->labels[index]->setText(setTextOptionBool(option_index, info->rounded_corners_fix));
|
||||
break;
|
||||
case MAIN_MENU_WINDOW_SCALING:
|
||||
this->labels[i]->setText(setTextOptionFloat(option_index, info->scaling));
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->scaling));
|
||||
break;
|
||||
case MAIN_MENU_MENU_SCALING:
|
||||
this->labels[i]->setText(setTextOptionFloat(option_index, info->menu_scaling_factor));
|
||||
this->labels[index]->setText(setTextOptionFloat(option_index, info->menu_scaling_factor));
|
||||
break;
|
||||
case MAIN_MENU_FULLSCREEN_SCALING:
|
||||
this->labels[i]->setText(setTextOptionDualPercentage(option_index, info->top_scaling, info->bot_scaling));
|
||||
this->labels[index]->setText(setTextOptionDualPercentage(option_index, info->top_scaling, info->bot_scaling));
|
||||
break;
|
||||
case MAIN_MENU_TOP_ROTATION:
|
||||
this->labels[i]->setText(setTextOptionInt(option_index, info->top_rotation));
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->top_rotation));
|
||||
break;
|
||||
case MAIN_MENU_BOTTOM_ROTATION:
|
||||
this->labels[i]->setText(setTextOptionInt(option_index, info->bot_rotation));
|
||||
this->labels[index]->setText(setTextOptionInt(option_index, info->bot_rotation));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -14,6 +14,9 @@ OptionSelectionMenu::~OptionSelectionMenu() {
|
||||
|
||||
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];
|
||||
@@ -33,18 +36,16 @@ void OptionSelectionMenu::initialize(bool font_load_success, sf::Font &text_font
|
||||
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->selectable_labels[this->title_center_id] = false;
|
||||
this->future_enabled_labels[this->back_x_id] = this->show_back_x;
|
||||
this->future_enabled_labels[this->title_id] = this->show_title;
|
||||
this->future_enabled_labels[this->title_center_id] = this->show_title && this->show_back_x;
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::class_setup() {
|
||||
this->num_elements_per_screen = 1;
|
||||
this->num_page_elements = 3;
|
||||
this->num_elements_displayed_per_screen = num_elements_per_screen + num_page_elements;
|
||||
this->num_vertical_slices = (num_elements_displayed_per_screen - (num_page_elements - 1));
|
||||
this->num_elements_start_id = 0;
|
||||
this->num_page_elements_start_id = num_elements_per_screen + num_elements_start_id;
|
||||
this->prev_page_id = num_page_elements_start_id;
|
||||
this->info_page_id = num_page_elements_start_id + 1;
|
||||
this->next_page_id = num_page_elements_start_id + 2;
|
||||
this->min_elements_text_scaling_factor = 3;
|
||||
this->width_factor_menu = 1;
|
||||
this->width_divisor_menu = 1;
|
||||
@@ -52,6 +53,29 @@ void OptionSelectionMenu::class_setup() {
|
||||
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 = 3;
|
||||
this->num_page_elements = 3;
|
||||
this->num_elements_displayed_per_screen = num_title_back_x_elements + num_elements_per_screen + 1 + num_page_elements;
|
||||
this->num_vertical_slices = num_elements_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 = num_elements_per_screen + elements_start_id + 1;
|
||||
this->back_x_id = title_back_x_start_id;
|
||||
this->title_id = title_back_x_start_id + 1;
|
||||
this->title_center_id = title_back_x_start_id + 2;
|
||||
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() {
|
||||
@@ -71,30 +95,28 @@ void OptionSelectionMenu::reset_data() {
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::decrement_selected_option() {
|
||||
if(this->future_data.option_selected < 0) {
|
||||
this->future_data.option_selected = this->elements_start_id;
|
||||
return;
|
||||
}
|
||||
if(this->future_data.option_selected >= this->page_elements_start_id)
|
||||
this->future_data.option_selected = this->page_elements_start_id;
|
||||
do {
|
||||
this->future_data.option_selected -= 1;
|
||||
if(this->future_data.option_selected <= 0) {
|
||||
this->future_data.option_selected = 0;
|
||||
return;
|
||||
}
|
||||
if((this->future_data.option_selected < (this->num_page_elements_start_id + this->num_page_elements)) && (this->future_data.option_selected >= num_page_elements_start_id)) {
|
||||
this->future_data.option_selected = this->num_page_elements_start_id - 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() {
|
||||
int starting_value = this->future_data.option_selected;
|
||||
if(starting_value < 0){
|
||||
this->future_data.option_selected = 0;
|
||||
if(this->future_data.option_selected < 0){
|
||||
this->future_data.option_selected = this->elements_start_id;
|
||||
return;
|
||||
}
|
||||
do {
|
||||
this->future_data.option_selected += 1;
|
||||
if(this->future_data.option_selected >= this->num_elements_displayed_per_screen) {
|
||||
this->future_data.option_selected = starting_value;
|
||||
return;
|
||||
}
|
||||
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]));
|
||||
}
|
||||
|
||||
@@ -112,22 +134,47 @@ std::string OptionSelectionMenu::get_string_option(int index) {
|
||||
return "Sample Text";
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::prepare_options() {
|
||||
int OptionSelectionMenu::get_num_pages() {
|
||||
int num_pages = 1 + ((this->get_num_options() - 1) / this->num_elements_per_screen);
|
||||
if(this->get_num_options() == (this->num_elements_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_elements_per_screen;
|
||||
int total_elements = this->get_num_options() - start;
|
||||
if(total_elements > this->num_elements_per_screen)
|
||||
if((num_pages > 1) && (total_elements > this->num_elements_per_screen))
|
||||
total_elements = this->num_elements_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);
|
||||
}
|
||||
if(this->show_back_x && this->show_title) {
|
||||
this->future_enabled_labels[this->title_center_id] = true;
|
||||
this->labels[this->title_center_id]->setText("");
|
||||
this->labels[this->title_center_id]->setShowText(true);
|
||||
}
|
||||
for(int i = 0; i < total_elements; i++) {
|
||||
this->future_enabled_labels[i] = true;
|
||||
this->labels[i]->setText(this->get_string_option(i + start));
|
||||
this->labels[i]->setShowText(true);
|
||||
this->future_enabled_labels[i + this->elements_start_id] = true;
|
||||
this->labels[i + this->elements_start_id]->setText(this->get_string_option(i + start));
|
||||
this->labels[i + this->elements_start_id]->setShowText(true);
|
||||
}
|
||||
if(num_pages > 1) {
|
||||
this->future_enabled_labels[this->info_page_id] = true;
|
||||
@@ -151,14 +198,18 @@ void OptionSelectionMenu::prepare_options() {
|
||||
|
||||
void OptionSelectionMenu::option_selection_handling() {
|
||||
int old_loaded_page = this->future_data.page;
|
||||
if(!(this->selectable_labels[this->future_data.option_selected] && this->future_enabled_labels[this->future_data.option_selected])) {
|
||||
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->num_elements_per_screen) {
|
||||
this->set_output_option(this->future_data.option_selected + (this->num_elements_per_screen * this->future_data.page));
|
||||
if(this->future_data.option_selected == this->back_x_id) {
|
||||
this->set_output_option(-1);
|
||||
this->last_action_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else if(this->future_data.option_selected < (this->num_elements_per_screen + this->elements_start_id + 1)) {
|
||||
this->set_output_option(this->future_data.option_selected - this->elements_start_id + (this->num_elements_per_screen * this->future_data.page));
|
||||
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)
|
||||
@@ -319,39 +370,56 @@ bool OptionSelectionMenu::poll(SFEvent &event_data) {
|
||||
}
|
||||
|
||||
void OptionSelectionMenu::draw(float scaling_factor, sf::RenderTarget &window) {
|
||||
sf::RectangleShape menu_rectangle(sf::Vector2f(this->loaded_data.menu_width, this->loaded_data.menu_height));
|
||||
menu_rectangle.setFillColor(sf::Color(30, 30, 60, 192));
|
||||
menu_rectangle.setPosition(this->loaded_data.pos_x, this->loaded_data.pos_y);
|
||||
window.draw(menu_rectangle);
|
||||
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) {
|
||||
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)
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_SELECTED);
|
||||
else
|
||||
this->labels[index]->setRectangleKind(TEXT_KIND_NORMAL);
|
||||
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((index == this->title_id) || (index == this->title_center_id))
|
||||
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;
|
||||
for(int i = 0; i < this->num_elements_per_screen; i++)
|
||||
if(this->future_enabled_labels[i])
|
||||
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_elements_per_screen + 1); i++)
|
||||
if(this->future_enabled_labels[i + 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->num_page_elements_start_id])
|
||||
if(this->future_enabled_labels[i + this->page_elements_start_id])
|
||||
has_bottom = true;
|
||||
if(has_bottom)
|
||||
num_elements += 1;
|
||||
@@ -383,16 +451,33 @@ void OptionSelectionMenu::base_prepare(float menu_scaling_factor, int view_size_
|
||||
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 top_divisor = 1;
|
||||
int title_start_x = 0;
|
||||
if(this->future_enabled_labels[this->title_center_id]) {
|
||||
top_divisor = 5;
|
||||
title_start_x = 1;
|
||||
}
|
||||
int num_rendered_y = 0;
|
||||
for(int i = 0; i < this->num_elements_per_screen; i++) {
|
||||
int index = i;
|
||||
if(this->future_enabled_labels[this->back_x_id]) {
|
||||
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(title_start_x, top_divisor, num_rendered_y, num_elements, this->title_id, text_scaling_factor, true);
|
||||
}
|
||||
if(this->future_enabled_labels[this->title_center_id]) {
|
||||
this->prepare_text_slices(top_divisor - title_start_x, top_divisor, num_rendered_y, num_elements, this->title_center_id, text_scaling_factor);
|
||||
}
|
||||
if(has_top)
|
||||
++num_rendered_y;
|
||||
for(int i = 0; i < (this->num_elements_per_screen + 1); i++) {
|
||||
int index = i + this->elements_start_id;
|
||||
if(this->future_enabled_labels[index]) {
|
||||
this->prepare_text_slices(0, 1, num_rendered_y, num_elements, index, text_scaling_factor);
|
||||
++num_rendered_y;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < this->num_page_elements; i++) {
|
||||
int index = i + this->num_page_elements_start_id;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -8,20 +8,10 @@ TextRectangle::TextRectangle(bool font_load_success, sf::Font &text_font) {
|
||||
if(this->font_load_success)
|
||||
this->actual_text.setFont(text_font);
|
||||
this->time_phase = 0;
|
||||
this->base_bg_color = new sf::Color(40, 40, 80, 192);
|
||||
this->selected_bg_color = new sf::Color(90, 150, 210, 192);
|
||||
this->success_bg_color = new sf::Color(90, 210, 90, 192);
|
||||
this->warning_bg_color = new sf::Color(200, 200, 90, 192);
|
||||
this->error_bg_color = new sf::Color(210, 90, 90, 192);
|
||||
this->reset_data(this->future_data);
|
||||
}
|
||||
|
||||
TextRectangle::~TextRectangle() {
|
||||
delete this->base_bg_color;
|
||||
delete this->selected_bg_color;
|
||||
delete this->success_bg_color;
|
||||
delete this->warning_bg_color;
|
||||
delete this->error_bg_color;
|
||||
}
|
||||
|
||||
void TextRectangle::setSize(int width, int height) {
|
||||
@@ -241,24 +231,32 @@ void TextRectangle::updateText(int x_limit) {
|
||||
globalBounds = this->actual_text.getGlobalBounds();
|
||||
this->actual_text.setPosition((int)((this->loaded_data.width - (globalBounds.width + (globalBounds.left * 2))) / 2), (int)((this->loaded_data.height - (globalBounds.height + (globalBounds.top * 2))) / 2));
|
||||
}
|
||||
sf::Color *used_color = this->base_bg_color;
|
||||
switch(this->loaded_data.kind) {
|
||||
case TEXT_KIND_NORMAL:
|
||||
this->curr_color = sf::Color(40, 40, 80, 192);
|
||||
break;
|
||||
case TEXT_KIND_SELECTED:
|
||||
used_color = this->selected_bg_color;
|
||||
this->curr_color = sf::Color(90, 150, 210, 192);
|
||||
break;
|
||||
case TEXT_KIND_SUCCESS:
|
||||
used_color = this->success_bg_color;
|
||||
this->curr_color = sf::Color(90, 210, 90, 192);
|
||||
break;
|
||||
case TEXT_KIND_WARNING:
|
||||
used_color = this->warning_bg_color;
|
||||
this->curr_color = sf::Color(200, 200, 90, 192);
|
||||
break;
|
||||
case TEXT_KIND_ERROR:
|
||||
used_color = this->error_bg_color;
|
||||
this->curr_color = sf::Color(210, 90, 90, 192);
|
||||
break;
|
||||
case TEXT_KIND_OPAQUE_ERROR:
|
||||
this->curr_color = sf::Color(160, 60, 60, 192);
|
||||
break;
|
||||
case TEXT_KIND_TITLE:
|
||||
this->curr_color = sf::Color(30, 30, 60, 192);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this->text_rect.out_tex.clear(*used_color);
|
||||
this->text_rect.out_tex.clear(this->curr_color);
|
||||
this->text_rect.out_tex.draw(this->actual_text);
|
||||
this->text_rect.out_tex.display();
|
||||
this->is_done_showing_text = false;
|
||||
|
||||
Reference in New Issue
Block a user