Preferences: refactored handling of initial page specification
This commit is contained in:
parent
2c5c3f5600
commit
09a095b8b1
9 changed files with 45 additions and 49 deletions
|
@ -1,3 +1,4 @@
|
|||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "map_command_handler.hpp"
|
||||
#include "chat_command_handler.hpp"
|
||||
#include "chat_events.hpp"
|
||||
|
@ -137,8 +138,8 @@ void chat_command_handler::do_remove()
|
|||
void chat_command_handler::do_display()
|
||||
{
|
||||
// TODO: add video and game config argument to chat_command_handler?
|
||||
preferences::show_preferences_dialog(CVideo::get_singleton(),
|
||||
game_config_manager::get()->game_config(), preferences::VIEW_FRIENDS);
|
||||
gui2::tpreferences::display(CVideo::get_singleton(), game_config_manager::get()->game_config(),
|
||||
preferences::VIEW_FRIENDS);
|
||||
}
|
||||
|
||||
void chat_command_handler::do_version() {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "gui/dialogs/edit_text.hpp"
|
||||
#include "gui/dialogs/editor/custom_tod.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/unit_list.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
|
@ -1087,7 +1088,7 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
|
|||
void editor_controller::preferences()
|
||||
{
|
||||
gui_->video().clear_all_help_strings();
|
||||
preferences::show_preferences_dialog(gui_->video(), game_config_);
|
||||
gui2::tpreferences::display(gui_->video(), game_config_);
|
||||
|
||||
gui_->redraw_everything();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "gui/dialogs/multiplayer/mp_create_game.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_login.hpp"
|
||||
#include "gui/dialogs/network_transmission.hpp"
|
||||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "hash.hpp"
|
||||
|
@ -616,7 +617,7 @@ static bool enter_configure_mode(CVideo& video, const config& game_config,
|
|||
static void do_preferences_dialog(CVideo& video, const config& game_config)
|
||||
{
|
||||
DBG_MP << "displaying preferences dialog" << std::endl;
|
||||
preferences::show_preferences_dialog(video, game_config);
|
||||
gui2::tpreferences::display(video, game_config);
|
||||
|
||||
/**
|
||||
* The screen size might have changed force an update of the size.
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "gui/dialogs/message.hpp" //for show error message
|
||||
#include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp" //for host game prompt
|
||||
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
|
||||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp" // for show_transient_message
|
||||
#include "gui/dialogs/title_screen.hpp" // for show_debug_clock_button
|
||||
#include "gui/widgets/settings.hpp" // for new_widgets
|
||||
|
@ -968,8 +969,7 @@ bool game_launcher::change_language()
|
|||
|
||||
void game_launcher::show_preferences()
|
||||
{
|
||||
preferences::show_preferences_dialog(video(),
|
||||
game_config_manager::get()->game_config());
|
||||
gui2::tpreferences::display(video(), game_config_manager::get()->game_config());
|
||||
}
|
||||
|
||||
void game_launcher::launch_game(RELOAD_GAME_DATA reload)
|
||||
|
|
|
@ -82,7 +82,7 @@ using namespace preferences;
|
|||
|
||||
REGISTER_DIALOG(preferences)
|
||||
|
||||
tpreferences::tpreferences(CVideo& video, const config& game_cfg)
|
||||
tpreferences::tpreferences(CVideo& video, const config& game_cfg, const PREFERENCE_VIEW& initial_view)
|
||||
: resolutions_(video.get_available_resolutions(true))
|
||||
, adv_preferences_cfg_()
|
||||
, friend_names_()
|
||||
|
@ -93,7 +93,7 @@ tpreferences::tpreferences(CVideo& video, const config& game_cfg)
|
|||
{"0.25", "0.5", "0.75", "1", "1.25", "1.5", "1.75", "2", "3", "4", "8", "16" })
|
||||
, visible_hotkeys_()
|
||||
, font_scaling_(font_scaling())
|
||||
, index_(0,0)
|
||||
, initial_index_(pef_view_map[initial_view])
|
||||
{
|
||||
for(const config& adv : game_cfg.child_range("advanced_preference")) {
|
||||
adv_preferences_cfg_.push_back(adv);
|
||||
|
@ -1129,7 +1129,7 @@ void tpreferences::pre_show(twindow& window)
|
|||
VALIDATE(selector.get_item_count() == pager.get_layer_count(),
|
||||
"The preferences pager and its selector listbox do not have the same number of items.");
|
||||
|
||||
const int main_index = index_in_pager_range(index_.first, pager);
|
||||
const int main_index = index_in_pager_range(initial_index_.first, pager);
|
||||
|
||||
// Loops through each pager layer and checks if it has both a tab bar
|
||||
// and stack. If so, it initilizes the options for the former and
|
||||
|
@ -1143,7 +1143,7 @@ void tpreferences::pre_show(twindow& window)
|
|||
|
||||
if(tab_pager && tab_selector) {
|
||||
const int ii = static_cast<int>(i);
|
||||
const int tab_index = index_in_pager_range(index_.second, *tab_pager);
|
||||
const int tab_index = index_in_pager_range(initial_index_.second, *tab_pager);
|
||||
const int to_select = (ii == main_index ? tab_index : 0);
|
||||
|
||||
// Initialize tabs for this page
|
||||
|
|
|
@ -28,9 +28,35 @@
|
|||
namespace hotkey {
|
||||
struct hotkey_command;
|
||||
}
|
||||
|
||||
namespace preferences {
|
||||
enum PREFERENCE_VIEW {
|
||||
VIEW_DEFAULT,
|
||||
VIEW_FRIENDS
|
||||
};
|
||||
|
||||
/**
|
||||
* Map containing page mappings that can be used to set the initally displayed page
|
||||
* of the dialog. The pair is in an 0-indexed toplevel stack/substack format, where
|
||||
* the first is the list of main Preference categories (such as General and Display)
|
||||
* and the second is any sub-stack found on that page.
|
||||
*
|
||||
* TODO: this isn't the most optimal solution, since if the order or number of pages
|
||||
* in either stack changes, this map needs to be updated. Optimally the stacked_widget
|
||||
* widget would allow specifying page by string id, but that would require changes to
|
||||
* tgenerator. It's something to look into, however.
|
||||
*/
|
||||
static std::map<PREFERENCE_VIEW, std::pair<int,int>> pef_view_map = {
|
||||
{VIEW_DEFAULT, {0,0}},
|
||||
{VIEW_FRIENDS, {4,1}}
|
||||
};
|
||||
}
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
using namespace preferences;
|
||||
|
||||
class tlistbox;
|
||||
class tmenu_button;
|
||||
class tcontrol;
|
||||
|
@ -41,25 +67,16 @@ class ttoggle_button;
|
|||
class tpreferences : public tdialog
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
tpreferences(CVideo& video, const config& game_cfg);
|
||||
tpreferences(CVideo& video, const config& game_cfg, const PREFERENCE_VIEW& initial_view);
|
||||
|
||||
/** The display function -- see @ref tdialog for more information. */
|
||||
static bool display(CVideo& video, const config& game_cfg)
|
||||
static void display(CVideo& video, const config& game_cfg, const PREFERENCE_VIEW initial_view = VIEW_DEFAULT)
|
||||
{
|
||||
tpreferences(video, game_cfg).show(video);
|
||||
return true;
|
||||
tpreferences(video, game_cfg, initial_view).show(video);
|
||||
}
|
||||
|
||||
typedef std::vector<const hotkey::hotkey_command*> t_visible_hotkeys;
|
||||
|
||||
void set_selected_index(std::pair<int, int> index)
|
||||
{
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
private:
|
||||
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const;
|
||||
|
@ -222,7 +239,7 @@ private:
|
|||
int font_scaling_;
|
||||
|
||||
// The page/tab index pairs for setting visible pages
|
||||
std::pair<int, int> index_;
|
||||
const std::pair<int, int>& initial_index_;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/dialogs/gamestate_inspector.hpp"
|
||||
#include "gui/dialogs/multiplayer/mp_change_control.hpp"
|
||||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "gui/dialogs/simple_item_selector.hpp"
|
||||
#include "gui/dialogs/edit_text.hpp"
|
||||
#include "gui/dialogs/game_stats.hpp"
|
||||
|
@ -193,7 +194,7 @@ void menu_handler::save_map()
|
|||
|
||||
void menu_handler::preferences()
|
||||
{
|
||||
preferences::show_preferences_dialog(gui_->video(), game_config_);
|
||||
gui2::tpreferences::display(gui_->video(), game_config_);
|
||||
// Needed after changing fullscreen/windowed mode or display resolution
|
||||
gui_->redraw_everything();
|
||||
}
|
||||
|
|
|
@ -48,23 +48,6 @@ void set_preference_display_settings()
|
|||
set_color_cursors(preferences::get("color_cursors", true));
|
||||
}
|
||||
|
||||
void show_preferences_dialog(CVideo& video, const config& game_cfg, const DIALOG_OPEN_TO initial_view)
|
||||
{
|
||||
gui2::tpreferences dlg(video, game_cfg);
|
||||
|
||||
switch (initial_view) {
|
||||
case VIEW_DEFAULT:
|
||||
// Default value (0,0) already set in tpreferences
|
||||
break;
|
||||
case VIEW_FRIENDS: {
|
||||
dlg.set_selected_index(std::make_pair(4, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dlg.show(video);
|
||||
}
|
||||
|
||||
void set_turbo(bool ison)
|
||||
{
|
||||
_set_turbo(ison);
|
||||
|
|
|
@ -21,12 +21,6 @@ class CVideo;
|
|||
#include <string>
|
||||
|
||||
namespace preferences {
|
||||
|
||||
enum DIALOG_OPEN_TO {
|
||||
VIEW_DEFAULT,
|
||||
VIEW_FRIENDS
|
||||
};
|
||||
|
||||
void set_preference_display_settings();
|
||||
|
||||
void set_turbo(bool ison);
|
||||
|
@ -39,8 +33,6 @@ namespace preferences {
|
|||
void set_idle_anim_rate(int rate);
|
||||
|
||||
void show_wesnothd_server_search(CVideo&);
|
||||
void show_preferences_dialog(CVideo& disp, const config& game_cfg,
|
||||
const DIALOG_OPEN_TO initial_view = VIEW_DEFAULT);
|
||||
bool show_theme_dialog(CVideo& disp);
|
||||
} // end namespace preferences
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue