The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
editor::context_manager Class Reference

#include <context_manager.hpp>

Public Types

using context_ptr = std::unique_ptr< map_context >
 

Public Member Functions

 context_manager (editor_display &gui, const config &game_config)
 
 ~context_manager ()
 
bool is_active_transitions_hotkey (const std::string &item)
 
size_t modified_maps (std::string &modified)
 
void set_update_transitions_mode (int mode)
 
bool toggle_update_transitions ()
 
bool clipboard_empty ()
 
map_fragmentget_clipboard ()
 
void fill_selection ()
 Fill the selection with the foreground terrain. More...
 
int current_context_index ()
 Index into the map_contexts_ array. More...
 
size_t open_maps (void)
 
void perform_refresh (const editor_action &action, bool drag_part=false)
 Perform an action on the current map_context, then refresh the display. More...
 
void save_all_maps (bool auto_save_windows=false)
 Save all maps, open dialog if not named yet, except when using auto_save_windows which will name unnamed maps "windows_N". More...
 
void save_map ()
 Save the map, open dialog if not named yet. More...
 
editor_displaygui ()
 
void refresh_all ()
 Refresh everything, i.e. More...
 
void apply_mask_dialog ()
 Display an apply mask dialog and process user input. More...
 
void create_mask_to_dialog ()
 Display an apply mask dialog and process user input. More...
 
void rename_area_dialog ()
 Display an dialog to querry a new id for an [time_area]. More...
 
void expand_open_maps_menu (std::vector< config > &items, int i)
 Menu expanding for open maps list. More...
 
void expand_load_mru_menu (std::vector< config > &items, int i)
 Menu expanding for most recent loaded list. More...
 
void expand_sides_menu (std::vector< config > &items, int i)
 Menu expanding for the map's player sides. More...
 
void expand_areas_menu (std::vector< config > &items, int i)
 Menu expanding for the map's defined areas. More...
 
void expand_time_menu (std::vector< config > &items, int i)
 Menu expanding for the map's defined areas. More...
 
void expand_local_time_menu (std::vector< config > &items, int i)
 Menu expanding for the map's defined areas. More...
 
void load_map_dialog (bool force_same_context=false)
 Display a load map dialog and process user input. More...
 
void load_mru_item (unsigned index, bool force_same_context=false)
 Open the specified entry from the recent files list. More...
 
void edit_scenario_dialog ()
 Display a scenario edit dialog and process user input. More...
 
void edit_side_dialog (int side_index)
 Display a side edit dialog and process user input. More...
 
void new_map_dialog ()
 Display a new map dialog and process user input. More...
 
void new_scenario_dialog ()
 Display a new map dialog and process user input. More...
 
void save_map_as_dialog ()
 Display a save map as dialog and process user input. More...
 
void save_scenario_as_dialog ()
 Display a save map as dialog and process user input. More...
 
void generate_map_dialog ()
 Display a generate random map dialog and process user input. More...
 
void resize_map_dialog ()
 Display a load map dialog and process user input. More...
 
size_t size ()
 
map_contextget_map_context ()
 Get the current map context object. More...
 
const editor_mapget_map () const
 Get the map from the current map context object - const version. More...
 
map_labelsget_labels ()
 
void set_default_dir (const std::string &str)
 Set the default dir (where the filebrowser is pointing at when there is no map file opened) More...
 
void refresh_after_action (bool drag_part=false)
 Refresh the display after an action has been performed. More...
 
editor_mapget_map ()
 Get the map from the current map context object. More...
 
void close_current_context ()
 Closes the active map context. More...
 
void switch_context (const int index, const bool force=false)
 Switches the context to the one under the specified index. More...
 
void load_map (const std::string &filename, bool new_context)
 Load a map given the filename. More...
 
void revert_map ()
 Revert the map by reloading it from disk. More...
 
void reload_map ()
 Reload the map after it has significantly changed (when e.g. More...
 

Private Member Functions

void init_map_generators (const config &game_config)
 init available random map generators More...
 
bool confirm_discard ()
 Shows an are-you-sure dialog if the map was modified. More...
 
const map_contextget_map_context () const
 Get the current map context object - const version. More...
 
template<typename... T>
int add_map_context (const T &...args)
 Add a map context. More...
 
int add_map_context_of (context_ptr &&mc)
 
template<typename... T>
void replace_map_context (const T &...args)
 Replace the current map context and refresh accordingly. More...
 
void replace_map_context_with (context_ptr &&mc)
 
void create_default_context ()
 Creates a default map context object, used to ensure there is always at least one. More...
 
bool save_map_as (const std::string &filename)
 Save the map under a given filename. More...
 
bool save_scenario_as (const std::string &filename)
 
bool write_map (bool display_confirmation=false)
 Save the map under a given filename. More...
 
bool write_scenario (bool display_confirmation=false)
 
void new_map (int width, int height, const t_translation::terrain_code &fill, bool new_context)
 Create a new map. More...
 
void new_scenario (int width, int height, const t_translation::terrain_code &fill, bool new_context)
 Create a new scenario. More...
 
size_t check_open_map (const std::string &fn) const
 Check if a map is already open. More...
 
bool check_switch_open_map (const std::string &fn)
 Check if a map is already open. More...
 
void set_window_title ()
 Displays the specified map name in the window titlebar. More...
 

Private Attributes

editor_displaygui_
 
const configgame_config_
 
std::string default_dir_
 Default directory for map load/save as dialogs. More...
 
std::vector< std::unique_ptr
< map_generator > > 
map_generators_
 Available random map generators. More...
 
map_generatorlast_map_generator_
 
int current_context_index_
 
int auto_update_transitions_
 Flag to rebuild terrain on every terrain change. More...
 
std::vector< context_ptrmap_contexts_
 The currently opened map context object. More...
 
map_fragment clipboard_
 Clipboard map_fragment – used for copy-paste. More...
 

Detailed Description

Definition at line 26 of file context_manager.hpp.

Member Typedef Documentation

Definition at line 29 of file context_manager.hpp.

Constructor & Destructor Documentation

editor::context_manager::context_manager ( editor_display gui,
const config game_config 
)
editor::context_manager::~context_manager ( )

Member Function Documentation

template<typename... T>
int editor::context_manager::add_map_context ( const T &...  args)
private

Add a map context.

The controller assumes ownership.

Returns
the index of the added map context in the map_contexts_ array

Definition at line 987 of file context_manager.cpp.

References map_contexts_.

Referenced by create_default_context(), new_map(), and new_scenario().

int editor::context_manager::add_map_context_of ( context_ptr &&  mc)
private

Definition at line 993 of file context_manager.cpp.

References map_contexts_.

Referenced by load_map().

void editor::context_manager::apply_mask_dialog ( )
size_t editor::context_manager::check_open_map ( const std::string &  fn) const
private

Check if a map is already open.

Returns
index of the map context containing the given filename, or map_contexts_.size() if not found.

Definition at line 864 of file context_manager.cpp.

References i, and map_contexts_.

Referenced by check_switch_open_map(), save_map_as(), and save_scenario_as().

bool editor::context_manager::check_switch_open_map ( const std::string &  fn)
private

Check if a map is already open.

If yes, switch to it and return true, return false otherwise.

Definition at line 874 of file context_manager.cpp.

References _(), check_open_map(), gui_, i, map_contexts_, gui2::show_transient_message(), switch_context(), and display::video().

Referenced by load_map().

bool editor::context_manager::clipboard_empty ( )
inline

Definition at line 46 of file context_manager.hpp.

References clipboard_, and editor::map_fragment::empty().

void editor::context_manager::close_current_context ( )

Closes the active map context.

Switches to a valid context afterward or creates a dummy one.

Definition at line 1031 of file context_manager.cpp.

References confirm_discard(), create_default_context(), current_context_index_, map_contexts_, and set_window_title().

bool editor::context_manager::confirm_discard ( )
private

Shows an are-you-sure dialog if the map was modified.

Returns
true if the user confirmed or the map was not modified, false otherwise

Definition at line 732 of file context_manager.cpp.

References _(), gui2::window::CANCEL, get_map_context(), gui_, gui2::show_message(), display::video(), and gui2::dialogs::message::yes_no_buttons.

Referenced by close_current_context(), and revert_map().

void editor::context_manager::create_default_context ( )
private

Creates a default map context object, used to ensure there is always at least one.

Except when we saved windows, in which case reopen them

Definition at line 1014 of file context_manager.cpp.

References add_map_context(), game_config::default_terrain, config::find_child(), game_config_, and t_translation::read_terrain_code().

Referenced by close_current_context(), and context_manager().

void editor::context_manager::create_mask_to_dialog ( )
int editor::context_manager::current_context_index ( )
inline

Index into the map_contexts_ array.

Definition at line 60 of file context_manager.hpp.

References current_context_index_.

void editor::context_manager::edit_scenario_dialog ( )
void editor::context_manager::edit_side_dialog ( int  side_index)
void editor::context_manager::expand_areas_menu ( std::vector< config > &  items,
int  i 
)
void editor::context_manager::expand_load_mru_menu ( std::vector< config > &  items,
int  i 
)

Menu expanding for most recent loaded list.

Definition at line 340 of file context_manager.cpp.

References _(), filesystem::base_name(), i, game_config::path, and preferences::editor::recent_files().

void editor::context_manager::expand_local_time_menu ( std::vector< config > &  items,
int  i 
)

Menu expanding for the map's defined areas.

Definition at line 446 of file context_manager.cpp.

References get_map_context(), editor::map_context::get_time_manager(), i, and tod_manager::times().

void editor::context_manager::expand_open_maps_menu ( std::vector< config > &  items,
int  i 
)
void editor::context_manager::expand_sides_menu ( std::vector< config > &  items,
int  i 
)

Menu expanding for the map's player sides.

Definition at line 403 of file context_manager.cpp.

References _(), get_map_context(), editor::map_context::get_teams(), i, t, and team::user_team_name().

void editor::context_manager::expand_time_menu ( std::vector< config > &  items,
int  i 
)

Menu expanding for the map's defined areas.

Definition at line 427 of file context_manager.cpp.

References get_map_context(), editor::map_context::get_time_manager(), i, and tod_manager::times().

void editor::context_manager::fill_selection ( )

Fill the selection with the foreground terrain.

Definition at line 743 of file context_manager.cpp.

References get_map(), editor::get_selected_bg_terrain(), and perform_refresh().

void editor::context_manager::generate_map_dialog ( )
map_fragment& editor::context_manager::get_clipboard ( )
inline

Definition at line 51 of file context_manager.hpp.

References clipboard_.

Referenced by editor::editor_toolkit::init_mouse_actions().

map_labels& editor::context_manager::get_labels ( )
inline
const editor_map& editor::context_manager::get_map ( ) const
inline

Get the map from the current map context object - const version.

Definition at line 164 of file context_manager.hpp.

References editor::map_context::get_map(), and get_map_context().

Referenced by fill_selection(), new_map_dialog(), new_scenario_dialog(), and resize_map_dialog().

editor_map& editor::context_manager::get_map ( )
inline

Get the map from the current map context object.

Definition at line 227 of file context_manager.hpp.

References editor::map_context::get_map(), and get_map_context().

map_context& editor::context_manager::get_map_context ( )
inline
const map_context& editor::context_manager::get_map_context ( ) const
inlineprivate

Get the current map context object - const version.

Definition at line 191 of file context_manager.hpp.

References current_context_index_, and map_contexts_.

editor_display& editor::context_manager::gui ( )
inline

Definition at line 85 of file context_manager.hpp.

References gui_.

Referenced by editor::map_context_refresher::refresh().

void editor::context_manager::init_map_generators ( const config game_config)
private

init available random map generators

Definition at line 681 of file context_manager.cpp.

References config::child_range(), create_map_generator(), ERR_ED, i, and map_generators_.

Referenced by context_manager().

bool editor::context_manager::is_active_transitions_hotkey ( const std::string &  item)
void editor::context_manager::load_map ( const std::string &  filename,
bool  new_context 
)
void editor::context_manager::load_map_dialog ( bool  force_same_context = false)
void editor::context_manager::load_mru_item ( unsigned  index,
bool  force_same_context = false 
)

Open the specified entry from the recent files list.

Definition at line 222 of file context_manager.cpp.

References load_map(), and preferences::editor::recent_files().

size_t editor::context_manager::modified_maps ( std::string &  modified)

Definition at line 183 of file context_manager.cpp.

References map_contexts_, and font::unicode_bullet.

void editor::context_manager::new_map ( int  width,
int  height,
const t_translation::terrain_code fill,
bool  new_context 
)
private
void editor::context_manager::new_map_dialog ( )

Display a new map dialog and process user input.

Definition at line 275 of file context_manager.cpp.

References _(), gui2::dialogs::editor_new_map::execute(), get_map(), editor::get_selected_bg_terrain(), gui_, gamemap::h(), h, new_map(), display::video(), gamemap::w(), and w.

void editor::context_manager::new_scenario ( int  width,
int  height,
const t_translation::terrain_code fill,
bool  new_context 
)
private
void editor::context_manager::new_scenario_dialog ( )

Display a new map dialog and process user input.

Definition at line 286 of file context_manager.cpp.

References _(), gui2::dialogs::editor_new_map::execute(), get_map(), editor::get_selected_bg_terrain(), gui_, gamemap::h(), h, new_scenario(), display::video(), gamemap::w(), and w.

size_t editor::context_manager::open_maps ( void  )
inline

Definition at line 65 of file context_manager.hpp.

References map_contexts_.

void editor::context_manager::perform_refresh ( const editor_action action,
bool  drag_part = false 
)

Perform an action on the current map_context, then refresh the display.

Definition at line 490 of file context_manager.cpp.

References get_map_context(), editor::map_context::perform_action(), and refresh_after_action().

Referenced by apply_mask_dialog(), create_mask_to_dialog(), fill_selection(), generate_map_dialog(), and resize_map_dialog().

void editor::context_manager::refresh_after_action ( bool  drag_part = false)
void editor::context_manager::refresh_all ( )
void editor::context_manager::reload_map ( )

Reload the map after it has significantly changed (when e.g.

the dimensions changed). This is necessary to avoid issues with parts of the map being cached in the display class.

Definition at line 149 of file context_manager.cpp.

References get_map_context(), gui_, refresh_all(), display::reload_map(), editor::map_context::reset_starting_position_labels(), and editor::map_context::set_needs_reload().

Referenced by editor::map_context_refresher::refresh(), and refresh_after_action().

void editor::context_manager::rename_area_dialog ( )
template<typename... T>
void editor::context_manager::replace_map_context ( const T &...  args)
private

Replace the current map context and refresh accordingly.

Definition at line 1000 of file context_manager.cpp.

References replace_map_context_with().

Referenced by new_map(), and new_scenario().

void editor::context_manager::replace_map_context_with ( context_ptr &&  mc)
private

Definition at line 1006 of file context_manager.cpp.

References current_context_index_, map_contexts_, and set_window_title().

Referenced by load_map(), and replace_map_context().

void editor::context_manager::resize_map_dialog ( )
void editor::context_manager::revert_map ( )

Revert the map by reloading it from disk.

Definition at line 937 of file context_manager.cpp.

References confirm_discard(), ERR_ED, editor::map_context::get_filename(), get_map_context(), and load_map().

void editor::context_manager::save_all_maps ( bool  auto_save_windows = false)

Save all maps, open dialog if not named yet, except when using auto_save_windows which will name unnamed maps "windows_N".

Also record all filenames for future reopening.

Definition at line 748 of file context_manager.cpp.

References current_context_index_, default_dir_, editor::map_context::get_filename(), get_map_context(), i, filesystem::is_directory(), map_contexts_, name(), s, save_map(), editor::map_context::set_filename(), and switch_context().

void editor::context_manager::save_map ( )
bool editor::context_manager::save_map_as ( const std::string &  filename)
private
void editor::context_manager::save_map_as_dialog ( )
bool editor::context_manager::save_scenario_as ( const std::string &  filename)
private
void editor::context_manager::save_scenario_as_dialog ( )
void editor::context_manager::set_default_dir ( const std::string &  str)
inline

Set the default dir (where the filebrowser is pointing at when there is no map file opened)

Definition at line 175 of file context_manager.hpp.

References default_dir_.

void editor::context_manager::set_update_transitions_mode ( int  mode)
inline
void editor::context_manager::set_window_title ( )
private
size_t editor::context_manager::size ( )
inline

Definition at line 152 of file context_manager.hpp.

References map_contexts_.

void editor::context_manager::switch_context ( const int  index,
const bool  force = false 
)

Switches the context to the one under the specified index.

Definition at line 1049 of file context_manager.cpp.

References current_context_index_, map_labels::enable(), get_labels(), utf8::index(), map_contexts_, set_window_title(), and WRN_ED.

Referenced by check_switch_open_map(), load_map(), new_map(), new_scenario(), and save_all_maps().

bool editor::context_manager::toggle_update_transitions ( )
bool editor::context_manager::write_map ( bool  display_confirmation = false)
private

Save the map under a given filename.

Displays an error message on failure.

Returns
true on success

Definition at line 849 of file context_manager.cpp.

References _(), e, get_map_context(), gui_, editor::map_context::save_map(), gui2::show_transient_message(), display::video(), and game::error::what().

Referenced by save_map(), and save_map_as().

bool editor::context_manager::write_scenario ( bool  display_confirmation = false)
private

Member Data Documentation

int editor::context_manager::auto_update_transitions_
private

Flag to rebuild terrain on every terrain change.

Definition at line 314 of file context_manager.hpp.

Referenced by is_active_transitions_hotkey(), refresh_after_action(), set_update_transitions_mode(), and toggle_update_transitions().

map_fragment editor::context_manager::clipboard_
private

Clipboard map_fragment – used for copy-paste.

Definition at line 320 of file context_manager.hpp.

Referenced by clipboard_empty(), and get_clipboard().

int editor::context_manager::current_context_index_
private
std::string editor::context_manager::default_dir_
private
const config& editor::context_manager::game_config_
private
editor_display& editor::context_manager::gui_
private
map_generator* editor::context_manager::last_map_generator_
private

Definition at line 309 of file context_manager.hpp.

Referenced by generate_map_dialog().

std::vector<context_ptr> editor::context_manager::map_contexts_
private
std::vector<std::unique_ptr<map_generator> > editor::context_manager::map_generators_
private

Available random map generators.

Definition at line 308 of file context_manager.hpp.

Referenced by generate_map_dialog(), and init_map_generators().


The documentation for this class was generated from the following files: