Make wesnoth --editor --load DIR (wesnoth -e -l DIR)...

...start the editor with a load map dialog pointed at DIR, and make
DIR the default map directory for the current session, per ESR's
request. Also make wesnoth -e foo work like wesnoth -e --load foo, and
change how -e MAP is processed internally.
This commit is contained in:
Tomasz Śniatowski 2009-04-13 21:09:35 +01:00
parent 7a60e7cc13
commit cf0c6e872b
6 changed files with 39 additions and 28 deletions

View file

@ -27,6 +27,10 @@ Version 1.7.0-svn:
* New feature: exporting of selection coordinates to system clipboard * New feature: exporting of selection coordinates to system clipboard
* Made auto terrain transition mode tri-state: on (editor2's on), partial * Made auto terrain transition mode tri-state: on (editor2's on), partial
(1.4 editor's on / editor2's off) and off (1.4's off). (1.4 editor's on / editor2's off) and off (1.4's off).
* Made "wesnoth -e FILE" work like "wesnoth -e --load FILE" (load the map)
* Made "wesnoth -e --load DIR" (and consequently "wesnoth -e DIR") set
DIR as the default map directory for the current session, and start with
the map load dialog open
* FormulaAI: * FormulaAI:
* Fixed bug #13230: added debug_float FormulaAI function to allow debugging * Fixed bug #13230: added debug_float FormulaAI function to allow debugging
via floating popups on the specified hex via floating popups on the specified hex

View file

@ -66,8 +66,11 @@ enables additional command mode options in-game
use special dummy locales to switch to any language even if that language use special dummy locales to switch to any language even if that language
isn't installed system-wide. isn't installed system-wide.
.TP .TP
.B -e, --editor .B -e, --editor \ file
start the in-game map editor directly. start the in-game map editor directly. If
.I file
is specified, equivalent to
.B -e --load
.TP .TP
.B --fps .B --fps
displays the number of frames per second the game is currently running displays the number of frames per second the game is currently running
@ -101,7 +104,7 @@ or
.B --editor .B --editor
option is used as well, starts the editor with the map from option is used as well, starts the editor with the map from
.I file .I file
open. open. If it is a directory, the editor will start with a load map dialog opened there.
.TP .TP
.BI --log- level = domain1 , domain2 , ... .BI --log- level = domain1 , domain2 , ...
sets the severity level of the log domains. sets the severity level of the log domains.

View file

@ -409,10 +409,15 @@ bool editor_controller::confirm_discard()
} }
} }
void editor_controller::load_map_dialog() void editor_controller::set_default_dir(const std::string& str)
{
default_dir_ = str;
}
void editor_controller::load_map_dialog(bool force_same_context /* = false */)
{ {
if (!use_mdi_ && !confirm_discard()) return; if (!use_mdi_ && !confirm_discard()) return;
std::string fn = get_map_context().get_filename(); std::string fn = directory_name(get_map_context().get_filename());
if (fn.empty()) { if (fn.empty()) {
fn = default_dir_; fn = default_dir_;
} }
@ -425,7 +430,7 @@ void editor_controller::load_map_dialog()
return; return;
} }
} }
load_map(fn, use_mdi_); load_map(fn, force_same_context ? false : use_mdi_);
} }
} }

View file

@ -123,8 +123,11 @@ class editor_controller : public controller_base,
/** Switches the context to the one under the specified index. */ /** Switches the context to the one under the specified index. */
void switch_context(const int index); void switch_context(const int index);
/** Set the default dir (where the filebrowser is pointing at when there is no map file opened) */
void set_default_dir(const std::string& str);
/** Display a load map dialog and process user input. */ /** Display a load map dialog and process user input. */
void load_map_dialog(); void load_map_dialog(bool force_same_context = false);
/** Display a new map dialog and process user input. */ /** Display a new map dialog and process user input. */
void new_map_dialog(); void new_map_dialog();

View file

@ -17,6 +17,7 @@
#include "../construct_dialog.hpp" #include "../construct_dialog.hpp"
#include "../gettext.hpp" #include "../gettext.hpp"
#include "../filesystem.hpp"
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
@ -30,28 +31,15 @@ EXIT_STATUS start(config& game_conf, CVideo& video, const std::string& filename
hotkey::deactivate_all_scopes(); hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL); hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
hotkey::set_scope_active(hotkey::SCOPE_EDITOR); hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
std::auto_ptr<map_context> mc(NULL); editor_controller editor(game_conf, video, NULL);
std::string map_error;
if (!filename.empty()) { if (!filename.empty()) {
try { if (is_directory(filename)) {
mc.reset(new map_context(game_conf, filename)); editor.set_default_dir(filename);
LOG_ED << "Map " << filename << " loaded. " editor.load_map_dialog(true);
<< mc->get_map().w() << " by " << mc->get_map().h() << "\n"; } else {
} catch (editor_map_load_exception& e) { editor.load_map(filename, false);
std::stringstream ss;
ss << "\"" << boost::replace_all_copy(filename, "\\", "\\\\") << "\"";
ss << ":\n";
ss << e.what();
map_error = ss.str();
ERR_ED << map_error << "\n";
mc.reset();
} }
} }
editor_controller editor(game_conf, video, mc.get());
mc.release();
if (!map_error.empty()) {
gui::message_dialog(editor.gui(), _("Error loading map"), map_error).show();
}
e = editor.main_loop(); e = editor.main_loop();
} catch (editor_exception& e) { } catch (editor_exception& e) {
ERR_ED << "Editor exception in editor2::start: " << e.what() << "\n"; ERR_ED << "Editor exception in editor2::start: " << e.what() << "\n";

View file

@ -401,6 +401,12 @@ game_controller::game_controller(int argc, char** argv) :
#ifndef DISABLE_EDITOR2 #ifndef DISABLE_EDITOR2
} else if(val == "-e" || val == "--editor") { } else if(val == "-e" || val == "--editor") {
jump_to_editor_ = true; jump_to_editor_ = true;
if(arg_+1 != argc_) {
if (argv_[arg_ + 1][0] != '-') {
++arg_;
loaded_game_ = argv_[arg_];
}
}
#endif #endif
} else if(val == "--dummy-locales") { } else if(val == "--dummy-locales") {
#ifdef USE_DUMMYLOCALES #ifdef USE_DUMMYLOCALES
@ -1718,7 +1724,8 @@ static int process_command_args(int argc, char** argv) {
<< " --dummy-locales enables dummy locales for switching to non-system\n" << " --dummy-locales enables dummy locales for switching to non-system\n"
<< " locales.\n" << " locales.\n"
#ifndef DISABLE_EDITOR2 #ifndef DISABLE_EDITOR2
<< " -e, --editor starts the in-game map editor directly.\n" << " -e, --editor [<file>] starts the in-game map editor directly. If <file>\n"
<< " is specified, equivalent to -e --load <file>.\n"
#endif #endif
<< " --fps displays the number of frames per second the\n" << " --fps displays the number of frames per second the\n"
<< " game is currently running at, in a corner of\n" << " game is currently running at, in a corner of\n"
@ -1735,7 +1742,8 @@ static int process_command_args(int argc, char** argv) {
#ifndef DISABLE_EDITOR2 #ifndef DISABLE_EDITOR2
<< " When launching the map editor via -e, the map\n" << " When launching the map editor via -e, the map\n"
<< " <file> is loaded, relative to the current\n" << " <file> is loaded, relative to the current\n"
<< " directory.\n" << " directory. If it is a directory, the editor\n"
<< " will start with a load map dialog opened there.\n"
#endif #endif
<< " --log-<level>=<domain1>,<domain2>,...\n" << " --log-<level>=<domain1>,<domain2>,...\n"
<< " sets the severity level of the log domains.\n" << " sets the severity level of the log domains.\n"