The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
editor_main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
17 
18 #include "gettext.hpp"
19 #include "filesystem.hpp"
21 
22 #include <boost/algorithm/string/replace.hpp>
23 
24 lg::log_domain log_editor("editor");
25 
26 namespace editor {
27 
28 EXIT_STATUS start(const config& game_conf, const std::string& filename /* = "" */,
29  bool take_screenshot /* = false */, const std::string& screenshot_filename /* = "map_screenshot.bmp" */)
30 {
32  try {
36  editor_controller editor(game_conf);
37  if (!filename.empty() && filesystem::file_exists (filename)) {
38  if (filesystem::is_directory(filename)) {
39  editor.context_manager_->set_default_dir(filename);
40  editor.context_manager_->load_map_dialog(true);
41  } else {
42  editor.context_manager_->load_map(filename, false);
43 
44  // HACK: this fixes an issue where the button overlays would be missing when
45  // the loaded map appears. Since we're gonna drop this ridiculous GUI1 drawing
46  // stuff in 1.15 I'm not going to waste time coming up with a better fix.
47  //
48  // Do note adding a redraw_everything call to context_manager::refresh_all also
49  // fixes the issue, but I'm pretty sure thats just because editor_controller::
50  // display_redraw_callback gets called, which then calls set_button_state.
51  //
52  // -- vultraz, 2018-02-24
53  editor.set_button_state();
54  }
55 
56  if (take_screenshot) {
57  editor.do_screenshot(screenshot_filename);
58  e = EXIT_NORMAL;
59  }
60  }
61 
62  if (!take_screenshot)
63  e = editor.main_loop();
64 
65  } catch (editor_exception& e) {
66  ERR_ED << "Editor exception in editor::start: " << e.what() << std::endl;
67  throw;
68  }
70  ERR_ED << "Possibly leaked " << editor_action::get_instance_count() << " action objects" << std::endl;
71  }
72 
73  return e;
74 }
75 
76 } //end namespace editor
const char * what() const NOEXCEPT
Definition: exceptions.hpp:37
std::vector< char_t > string
void do_screenshot(const std::string &screenshot_filename="map_screenshot.bmp")
Takes a screenshot.
lg::log_domain log_editor("editor")
void set_scope_active(scope s, bool set)
static int get_instance_count()
Debugging aid.
Base class for editor actions.
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Manage the empty-palette in the editor.
Definition: action.cpp:29
void deactivate_all_scopes()
EXIT_STATUS start(const config &game_conf, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Definition: editor_main.cpp:28
Declarations for File-IO.
EXIT_STATUS main_loop()
Editor main loop.
#define ERR_ED
#define e
const std::unique_ptr< context_manager > context_manager_
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.