The Battle for Wesnoth
1.17.4+dev
editor
editor_main.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2008 - 2022
3
by Tomasz Sniatowski <kailoran@gmail.com>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#define GETTEXT_DOMAIN "wesnoth-editor"
17
18
#include "
editor/controller/editor_controller.hpp
"
19
20
#include "
gettext.hpp
"
21
#include "
filesystem.hpp
"
22
#include "
editor/action/action_base.hpp
"
23
24
#include <boost/algorithm/string/replace.hpp>
25
26
lg::log_domain
log_editor
(
"editor"
);
27
28
namespace
editor
{
29
30
EXIT_STATUS
start
(
const
std::string& filename
/* = "" */
,
31
bool
take_screenshot
/* = false */
,
const
std::string& screenshot_filename
/* = "map_screenshot.png" */
)
32
{
33
EXIT_STATUS
e
=
EXIT_ERROR
;
34
try
{
35
hotkey::scope_changer
h_;
36
hotkey::deactivate_all_scopes
();
37
hotkey::set_scope_active
(
hotkey::SCOPE_EDITOR
);
38
editor_controller
editor
;
39
if
(!filename.empty() &&
filesystem::file_exists
(filename)) {
40
if
(
filesystem::is_directory
(filename)) {
41
editor.
context_manager_
->set_default_dir(filename);
42
editor.
context_manager_
->load_map_dialog(
true
);
43
}
else
{
44
editor.
context_manager_
->load_map(filename,
false
);
45
46
// HACK: this fixes an issue where the button overlays would be missing when
47
// the loaded map appears. Since we're gonna drop this ridiculous GUI1 drawing
48
// stuff in 1.15 I'm not going to waste time coming up with a better fix.
49
//
50
// Do note adding a redraw_everything call to context_manager::refresh_all also
51
// fixes the issue, but I'm pretty sure thats just because editor_controller::
52
// display_redraw_callback gets called, which then calls set_button_state.
53
//
54
// -- vultraz, 2018-02-24
55
editor.
set_button_state
();
56
}
57
58
if
(take_screenshot) {
59
editor.
do_screenshot
(screenshot_filename);
60
e =
EXIT_NORMAL
;
61
}
62
}
63
64
if
(!take_screenshot)
65
e = editor.
main_loop
();
66
67
}
catch
(
const
editor_exception
& e) {
68
ERR_ED
<<
"Editor exception in editor::start: "
<< e.
what
() << std::endl;
69
throw
;
70
}
71
if
(
editor_action::get_instance_count
() != 0) {
72
ERR_ED
<<
"Possibly leaked "
<<
editor_action::get_instance_count
() <<
" action objects"
<< std::endl;
73
}
74
75
return
e
;
76
}
77
78
}
//end namespace editor
gettext.hpp
game_config::editor
bool editor
Definition:
game_config.cpp:106
log_editor
lg::log_domain log_editor("editor")
hotkey::set_scope_active
void set_scope_active(scope s, bool set)
Definition:
hotkey_command.cpp:336
filesystem::file_exists
static bool file_exists(const bfs::path &fpath)
Definition:
filesystem.cpp:263
lg::log_domain
Definition:
log.hpp:105
hotkey::SCOPE_EDITOR
Definition:
hotkey_command.hpp:37
editor::editor_action::get_instance_count
static int get_instance_count()
Debugging aid.
Definition:
action_base.hpp:101
action_base.hpp
Base class for editor actions.
editor_controller.hpp
editor::editor_controller
The editor_controller class contains the mouse and keyboard event handling routines for the editor...
Definition:
editor_controller.hpp:68
hotkey::command_executor_default::set_button_state
void set_button_state()
Definition:
command_executor.cpp:672
editor::start
EXIT_STATUS start(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:30
editor::EXIT_NORMAL
Definition:
editor_main.hpp:25
editor::editor_exception
Definition:
editor_common.hpp:41
filesystem::is_directory
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Definition:
filesystem.cpp:1101
editor
Manage the empty-palette in the editor.
Definition:
action.cpp:30
game::error::what
const char * what() const noexcept
Definition:
exceptions.hpp:36
hotkey::deactivate_all_scopes
void deactivate_all_scopes()
Definition:
hotkey_command.cpp:329
editor::EXIT_ERROR
Definition:
editor_main.hpp:28
filesystem.hpp
Declarations for File-IO.
editor::editor_controller::do_screenshot
void do_screenshot(const std::string &screenshot_filename="map_screenshot.png")
Takes a screenshot.
Definition:
editor_controller.cpp:192
editor::EXIT_STATUS
EXIT_STATUS
Definition:
editor_main.hpp:24
hotkey::scope_changer
Definition:
hotkey_command.hpp:307
editor::editor_controller::main_loop
EXIT_STATUS main_loop()
Editor main loop.
Definition:
editor_controller.cpp:174
ERR_ED
#define ERR_ED
Definition:
editor_common.hpp:34
e
#define e
editor::editor_controller::context_manager_
const std::unique_ptr< context_manager > context_manager_
Definition:
editor_controller.hpp:250
Generated by
1.8.13