Editor2 quit and quit do desktop features,

...confirm quit message different if map was modified
This commit is contained in:
Tomasz Śniatowski 2008-07-15 23:25:29 +01:00
parent 44be046b7b
commit 32bc25963b
7 changed files with 73 additions and 21 deletions

View file

@ -8,6 +8,13 @@
#endif
#enddef
[hotkey]
command="editor-quit-to-desktop"
key="q"
shift=yes
{IF_APPLE_CMD_ELSE_CTRL}
[/hotkey]
[hotkey]
command="editor-map-save"
description="Save map"

View file

@ -119,7 +119,7 @@
id=menu-editor-file
title= _ "File"
image=lite
items=editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-quit
items=editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,quit,editor-quit-to-desktop
ref=top-panel
rect="=+3,=+1,+100,=-4"
xanchor=fixed

View file

@ -37,7 +37,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
: controller_base(SDL_GetTicks(), game_config, video)
, mouse_handler_base(map_)
, map_(editor_map::new_map(game_config, 44, 33, t_translation::GRASS_LAND))
, gui_(NULL)
, gui_(NULL), actions_since_save_(0), do_quit_(false), quit_mode_(EXIT_ERROR)
{
hotkey::deactivate_all_scopes();
hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
@ -87,11 +87,26 @@ editor_controller::~editor_controller()
delete prefs_disp_manager_;
}
void editor_controller::main_loop()
EXIT_STATUS editor_controller::main_loop()
{
for(;;) {
while (!do_quit_) {
play_slice();
}
return quit_mode_;
}
void editor_controller::quit_confirm(EXIT_STATUS mode)
{
std::string message = _("Do you really want to quit?");
if (actions_since_save_ != 0) {
message += " ";
message += _("There are unsaved changes in the map.");
}
int res = gui::dialog(gui(),_("Quit"),message,gui::YES_NO).show();
if (res == 0) {
do_quit_ = true;
quit_mode_ = mode;
}
}
void editor_controller::load_map_dialog()
@ -128,6 +143,7 @@ void editor_controller::set_map(const editor_map& map)
map_ = map;
clear_stack(undo_stack_);
clear_stack(redo_stack_);
actions_since_save_ = 0;
refresh_all();
}
@ -146,12 +162,13 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_MUTE:
case HOTKEY_PREFERENCES:
case HOTKEY_HELP:
case HOTKEY_QUIT_GAME:
return true; //general hotkeys we can always do
case HOTKEY_UNDO:
return can_undo();
case HOTKEY_REDO:
return can_redo();
case HOTKEY_EDITOR_QUIT:
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
case HOTKEY_EDITOR_MAP_NEW:
case HOTKEY_EDITOR_MAP_LOAD:
case HOTKEY_EDITOR_MAP_SAVE_AS:
@ -194,6 +211,12 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
SCOPE_ED;
using namespace hotkey;
switch (command) {
case HOTKEY_QUIT_GAME:
quit_confirm(EXIT_NORMAL);
return true;
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
quit_confirm(EXIT_QUIT_TO_DESKTOP);
return true;
case HOTKEY_EDITOR_TOOL_PAINT:
set_mouse_action(mouse_actions_["paint"]);
return true;
@ -247,6 +270,13 @@ void editor_controller::perform_action(const editor_action& action)
SCOPE_ED;
LOG_ED << "Performing action " << action.get_id() << ", actions count is " << action.get_instance_count() << "\n";
editor_action* undo = action.perform(map_);
if (actions_since_save_ < 0) {
//set to a value that will make it impossible to get to zero, as at this point
//it is no longer possible to get back the original map state using undo/redo
actions_since_save_ = undo_stack_.size() + 1;
} else {
++actions_since_save_;
}
undo_stack_.push_back(undo);
trim_stack(undo_stack_);
clear_stack(redo_stack_);
@ -303,12 +333,22 @@ bool editor_controller::can_redo() const
void editor_controller::undo()
{
perform_action_between_stacks(undo_stack_, redo_stack_);
if (can_undo()) {
perform_action_between_stacks(undo_stack_, redo_stack_);
--actions_since_save_;
} else {
ERR_ED << "undo() called with an empty undo stack";
}
}
void editor_controller::redo()
{
perform_action_between_stacks(redo_stack_, undo_stack_);
if (can_redo()) {
perform_action_between_stacks(redo_stack_, undo_stack_);
++actions_since_save_;
} else {
ERR_ED << "redo() called with an empty redo stack";
}
}
void editor_controller::perform_action_between_stacks(action_stack& from, action_stack& to)

View file

@ -19,6 +19,7 @@
#include "editor_common.hpp"
#include "editor_display.hpp"
#include "editor_map.hpp"
#include "editor_main.hpp"
#include "editor_mouse_handler.hpp"
#include "editor_mode.hpp"
@ -42,7 +43,9 @@ class editor_controller : public controller_base,
public:
editor_controller(const config &game_config, CVideo& video);
~editor_controller();
void main_loop();
EXIT_STATUS main_loop();
void hotkey_quit();
void quit_confirm(EXIT_STATUS status);
void load_map_dialog();
void load_map(const std::string& filename);
void set_map(const editor_map& map);
@ -148,6 +151,11 @@ class editor_controller : public controller_base,
*/
static const int max_action_stack_size_;
int actions_since_save_;
bool do_quit_;
EXIT_STATUS quit_mode_;
std::vector<brush> brushes_;
std::map<std::string, mouse_action*> mouse_actions_;
};

View file

@ -16,22 +16,12 @@
#include "editor_common.hpp"
#include "editor_controller.hpp"
#include "config.hpp"
#include "filesystem.hpp"
#include "game_preferences.hpp"
#include "gamestatus.hpp"
#include "log.hpp"
#include "wml_exception.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
#include "serialization/string_utils.hpp"
namespace editor2 {
EXIT_STATUS start(config& game_conf, CVideo& video)
{
editor_controller editor(game_conf, video);
editor.main_loop();
return EXIT_ERROR;
return editor.main_loop();
}
} //end namespace editor2

View file

@ -131,7 +131,7 @@ const struct {
{ hotkey::HOTKEY_EDIT_UPDATE, "editupdate", N_("Update transitions"), true, hotkey::SCOPE_GENERAL },
#ifdef USE_EDITOR2
{ hotkey::HOTKEY_EDITOR_QUIT, "editor-quit", N_("Quit Editor"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_QUIT_TO_DESKTOP, "editor-quit-to-desktop", N_("Quit to Desktop"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_NEW, "editor-map-new", N_("New Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_LOAD, "editor-map-load", N_("Load Map"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_MAP_SAVE, "editor-map-save", N_("Save Map"), false, hotkey::SCOPE_EDITOR },
@ -198,6 +198,7 @@ std::vector<hotkey::hotkey_item> hotkeys_;
hotkey::hotkey_item null_hotkey_;
const std::string scope_strings_[] = {"general", "game", "editor"};
const std::string scope_labels_[] = {"Common", "Game", "Editor"};
bool scope_active_[hotkey::SCOPE_COUNT] = {true, false};
}
@ -226,6 +227,11 @@ const std::string& get_scope_string(scope s)
return scope_strings_[s];
}
const std::string& get_scope_label(scope s)
{
return scope_labels_[s];
}
static void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor);
const std::string CLEARED_TEXT = "__none__";

View file

@ -71,7 +71,7 @@ enum HOTKEY_COMMAND {
HOTKEY_EDIT_REFRESH, HOTKEY_EDIT_UPDATE, HOTKEY_EDIT_AUTO_UPDATE,
#ifdef USE_EDITOR2
HOTKEY_EDITOR_QUIT,
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
HOTKEY_EDITOR_MAP_NEW, HOTKEY_EDITOR_MAP_LOAD, HOTKEY_EDITOR_MAP_SAVE,
HOTKEY_EDITOR_MAP_SAVE_AS, HOTKEY_EDITOR_MAP_REVERT,
HOTKEY_EDITOR_TOOL_NEXT, HOTKEY_EDITOR_TOOL_PAINT, HOTKEY_EDITOR_TOOL_FILL,
@ -103,6 +103,7 @@ void deactivate_all_scopes();
void set_scope_active(scope s, bool set = true);
bool is_scope_active(scope s);
const std::string& get_scope_string(scope s);
const std::string& get_scope_label(scope s);
class hotkey_item {
public: