editor2: add mask applying and creating to the editor.
possibly under-featured, needs testing
This commit is contained in:
parent
cd1faedd3f
commit
39d377190f
10 changed files with 139 additions and 20 deletions
|
@ -130,7 +130,7 @@
|
|||
id=menu-editor-edit
|
||||
title= _ "Edit"
|
||||
image=lite
|
||||
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-select-all,editor-select-inverse,editor-select-none,editor-selection-fill,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize,editor-clipboard-rotate-cw,editor-clipboard-rotate-ccw,editor-clipboard-flip-horizontal,editor-clipboard-flip-vertical
|
||||
items=undo,redo,editor-cut,editor-copy,editor-paste, editor-select-all,editor-select-inverse,editor-select-none, editor-selection-fill,editor-selection-rotate,editor-selection-flip, editor-selection-generate,editor-selection-randomize, editor-clipboard-rotate-cw,editor-clipboard-rotate-ccw, editor-clipboard-flip-horizontal,editor-clipboard-flip-vertical
|
||||
rect="+2,=,+100,="
|
||||
xanchor=fixed
|
||||
yanchor=fixed
|
||||
|
@ -140,7 +140,7 @@
|
|||
id=menu-editor-map
|
||||
title= _ "Map"
|
||||
image=lite
|
||||
items=editor-map-resize,editor-map-rotate,editor-map-generate,editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-refresh-image-cache,editor-draw-coordinates,editor-draw-terrain-codes
|
||||
items=editor-map-resize,editor-map-rotate,editor-map-generate, editor-map-apply-mask,editor-map-create-mask-to, editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-refresh-image-cache, editor-draw-coordinates,editor-draw-terrain-codes
|
||||
rect="+2,=,+100,="
|
||||
xanchor=fixed
|
||||
yanchor=fixed
|
||||
|
|
|
@ -289,7 +289,6 @@ void editor_action_deselect::perform_without_undo(map_context& mc) const
|
|||
|
||||
editor_action_deselect* editor_action_select_all::perform(map_context& mc) const
|
||||
{
|
||||
|
||||
std::set<gamemap::location> current = mc.get_map().selection();
|
||||
mc.get_map().select_all();
|
||||
std::set<gamemap::location> all = mc.get_map().selection();
|
||||
|
@ -308,7 +307,6 @@ void editor_action_select_all::perform_without_undo(map_context& mc) const
|
|||
|
||||
editor_action_select* editor_action_select_none::perform(map_context& mc) const
|
||||
{
|
||||
|
||||
std::set<gamemap::location> current = mc.get_map().selection();
|
||||
mc.get_map().clear_selection();
|
||||
mc.set_everything_changed();
|
||||
|
@ -338,6 +336,18 @@ void editor_action_resize_map::perform_without_undo(map_context& mc) const
|
|||
mc.set_needs_reload();
|
||||
}
|
||||
|
||||
void editor_action_apply_mask::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
mc.get_map().overlay(mask_, config(), 0, 0);
|
||||
mc.set_needs_terrain_rebuild();
|
||||
}
|
||||
|
||||
void editor_action_create_mask::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
mc.get_map() = editor_map(mc.get_map().mask_to(target_));
|
||||
mc.set_needs_terrain_rebuild();
|
||||
}
|
||||
|
||||
void editor_action_rotate_map::perform_without_undo(map_context& /*mc*/) const
|
||||
{
|
||||
throw editor_action_not_implemented();
|
||||
|
|
|
@ -403,6 +403,30 @@ class editor_action_rotate_map : public editor_action
|
|||
int angle_;
|
||||
};
|
||||
|
||||
class editor_action_apply_mask : public editor_action
|
||||
{
|
||||
public:
|
||||
editor_action_apply_mask(const gamemap& mask)
|
||||
: mask_(mask)
|
||||
{
|
||||
}
|
||||
void perform_without_undo(map_context& mc) const;
|
||||
private:
|
||||
gamemap mask_;
|
||||
};
|
||||
|
||||
class editor_action_create_mask : public editor_action
|
||||
{
|
||||
public:
|
||||
editor_action_create_mask(const gamemap& target)
|
||||
: target_(target)
|
||||
{
|
||||
}
|
||||
void perform_without_undo(map_context& mc) const;
|
||||
private:
|
||||
gamemap target_;
|
||||
};
|
||||
|
||||
//plot a route between two points
|
||||
class editor_action_plot_route : public editor_action_location_terrain
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#define EDITOR2_ACTION_BASE_HPP_INCLUDED
|
||||
|
||||
#include "editor_common.hpp"
|
||||
|
||||
#include "../gettext.hpp"
|
||||
#include <string>
|
||||
|
||||
|
||||
|
@ -96,7 +96,7 @@ class editor_action
|
|||
//TODO: add messages etc
|
||||
struct editor_action_exception : public editor_exception
|
||||
{
|
||||
editor_action_exception(const char* msg)
|
||||
editor_action_exception(const std::string& msg)
|
||||
: editor_exception(msg)
|
||||
{
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ struct editor_action_exception : public editor_exception
|
|||
struct editor_action_not_implemented : public editor_action_exception
|
||||
{
|
||||
editor_action_not_implemented()
|
||||
: editor_action_exception("Action not implemented")
|
||||
: editor_action_exception(_("Action not implemented"))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -115,7 +115,7 @@ struct editor_action_not_implemented : public editor_action_exception
|
|||
struct editor_action_creation_fail : public editor_action_exception
|
||||
{
|
||||
editor_action_creation_fail()
|
||||
: editor_action_exception("Error creating action object")
|
||||
: editor_action_exception(_("Error creating action object"))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -375,6 +375,50 @@ void editor_controller::generate_map_dialog()
|
|||
}
|
||||
}
|
||||
|
||||
void editor_controller::apply_mask_dialog()
|
||||
{
|
||||
std::string fn = get_map_context().get_filename();
|
||||
if (fn.empty()) {
|
||||
fn = default_dir_;
|
||||
}
|
||||
int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose a mask to apply"));
|
||||
if (res == 0) {
|
||||
try {
|
||||
editor_map mask = editor_map::load_from_file(game_config_, fn);
|
||||
editor_action_apply_mask a(mask);
|
||||
perform_refresh(a);
|
||||
} catch (editor_map_load_exception& e) {
|
||||
gui::message_dialog(gui(), _("Error loading mask"), e.what()).show();
|
||||
return;
|
||||
} catch (editor_action_exception& e) {
|
||||
gui::message_dialog(gui(), _("Error"), e.what()).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void editor_controller::create_mask_to_dialog()
|
||||
{
|
||||
std::string fn = get_map_context().get_filename();
|
||||
if (fn.empty()) {
|
||||
fn = default_dir_;
|
||||
}
|
||||
int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose target map"));
|
||||
if (res == 0) {
|
||||
try {
|
||||
editor_map map = editor_map::load_from_file(game_config_, fn);
|
||||
editor_action_create_mask a(map);
|
||||
perform_refresh(a);
|
||||
} catch (editor_map_load_exception& e) {
|
||||
gui::message_dialog(gui(), _("Error loading map"), e.what()).show();
|
||||
return;
|
||||
} catch (editor_action_exception& e) {
|
||||
gui::message_dialog(gui(), _("Error"), e.what()).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void editor_controller::resize_map_dialog()
|
||||
{
|
||||
gui2::teditor_resize_map dialog;
|
||||
|
@ -609,6 +653,8 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
|
|||
case HOTKEY_EDITOR_SELECT_NONE:
|
||||
case HOTKEY_EDITOR_MAP_RESIZE:
|
||||
case HOTKEY_EDITOR_MAP_GENERATE:
|
||||
case HOTKEY_EDITOR_MAP_APPLY_MASK:
|
||||
case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
|
||||
case HOTKEY_EDITOR_REFRESH:
|
||||
case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
|
||||
case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
|
||||
|
@ -741,6 +787,12 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
case HOTKEY_EDITOR_MAP_GENERATE:
|
||||
generate_map_dialog();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_MAP_APPLY_MASK:
|
||||
apply_mask_dialog();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_MAP_CREATE_MASK_TO:
|
||||
create_mask_to_dialog();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_MAP_RESIZE:
|
||||
resize_map_dialog();
|
||||
return true;
|
||||
|
|
|
@ -110,6 +110,12 @@ class editor_controller : public controller_base,
|
|||
/** Display a generate random map dialog and process user input. */
|
||||
void generate_map_dialog();
|
||||
|
||||
/** Display an apply mask dialog and process user input. */
|
||||
void apply_mask_dialog();
|
||||
|
||||
/** Display an apply mask dialog and process user input. */
|
||||
void create_mask_to_dialog();
|
||||
|
||||
/** Display a load map dialog and process user input. */
|
||||
void resize_map_dialog();
|
||||
|
||||
|
|
|
@ -50,6 +50,13 @@ editor_map::editor_map(const config& /*terrain_cfg*/, const gamemap& map)
|
|||
sanity_check();
|
||||
}
|
||||
|
||||
editor_map::editor_map(const gamemap& map)
|
||||
: gamemap(map)
|
||||
, selection_()
|
||||
{
|
||||
sanity_check();
|
||||
}
|
||||
|
||||
editor_map editor_map::load_from_file(const config& game_config, const std::string& filename)
|
||||
{
|
||||
std::string map_string = read_file(filename);
|
||||
|
@ -62,13 +69,13 @@ editor_map editor_map::load_from_file(const config& game_config, const std::stri
|
|||
return new_map;
|
||||
} catch (gamemap::incorrect_format_exception& e) {
|
||||
WRN_ED << "format error in load map " << filename << "\n";
|
||||
std::string message = _("There was a format error while loading the map:");
|
||||
std::string message = _("There was a format error while loading the file:");
|
||||
message += "\n";
|
||||
message += e.msg_;
|
||||
throw editor_map_load_exception(filename, message);
|
||||
} catch (twml_exception& e) {
|
||||
WRN_ED << "wml error in load map " << filename << "\n";
|
||||
std::string message = _("There was a wml error while loading the map:");
|
||||
std::string message = _("There was a wml error while loading the file:");
|
||||
message += "\n";
|
||||
message += e.user_message;
|
||||
throw editor_map_load_exception(filename, message);
|
||||
|
@ -257,6 +264,23 @@ void editor_map::resize(int width, int height, int x_offset, int y_offset,
|
|||
sanity_check();
|
||||
}
|
||||
|
||||
gamemap editor_map::mask_to(const gamemap& target) const
|
||||
{
|
||||
if (target.w() != w() || target.h() != h()) {
|
||||
throw editor_action_exception(_("The size of the target map is different from the current map"));
|
||||
}
|
||||
gamemap mask(target);
|
||||
gamemap::location iter;
|
||||
for (iter.x = 0 ; iter.x < w(); ++iter.x) {
|
||||
for (iter.y = 0; iter.y < h(); ++iter.y) {
|
||||
if (target.get_terrain(iter) == get_terrain(iter)) {
|
||||
mask.set_terrain(iter, t_translation::FOGGED);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
void editor_map::swap_starting_position(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int pos1 = is_starting_position(location(x1, y1));
|
||||
|
|
|
@ -63,6 +63,8 @@ public:
|
|||
|
||||
editor_map(const config& terrain_cfg, const gamemap& map);
|
||||
|
||||
explicit editor_map(const gamemap& map);
|
||||
|
||||
static editor_map load_from_file(const config& game_config, const std::string& filename);
|
||||
|
||||
~editor_map();
|
||||
|
@ -138,16 +140,12 @@ public:
|
|||
*/
|
||||
void resize(int width, int height, int x_offset, int y_offset,
|
||||
t_translation::t_terrain filler = t_translation::NONE_TERRAIN);
|
||||
|
||||
/**
|
||||
* Flip the map along the X axis. Seems somewhat broken, was so in the old editor.
|
||||
|
||||
/**
|
||||
* A sort-of diff operation returning a mask that, when applied to the current editor_map,
|
||||
* will transform it into the target map.
|
||||
*/
|
||||
void flip_x();
|
||||
|
||||
/**
|
||||
* Flip the map along the Y axis. Seems somewhat broken, was so in the old editor.
|
||||
*/
|
||||
void flip_y();
|
||||
gamemap mask_to(const gamemap& target) const;
|
||||
|
||||
protected:
|
||||
void swap_starting_position(int x1, int y1, int x2, int y2);
|
||||
|
|
|
@ -161,6 +161,10 @@ const struct {
|
|||
N_("Rotate Map"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_GENERATE, "editor-map-generate",
|
||||
N_("Generate Map"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_APPLY_MASK, "editor-map-apply-mask",
|
||||
N_("Apply a Mask"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_CREATE_MASK_TO, "editor-map-create-mask-to",
|
||||
N_("Create Mask"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_REFRESH, "editor-refresh",
|
||||
N_("Refresh Display"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_UPDATE_TRANSITIONS, "editor-update-transitions",
|
||||
|
|
|
@ -79,7 +79,8 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_EDITOR_SELECTION_FILL,
|
||||
HOTKEY_EDITOR_SELECTION_GENERATE, HOTKEY_EDITOR_SELECTION_RANDOMIZE,
|
||||
HOTKEY_EDITOR_MAP_RESIZE, HOTKEY_EDITOR_MAP_ROTATE,
|
||||
HOTKEY_EDITOR_MAP_GENERATE,
|
||||
HOTKEY_EDITOR_MAP_GENERATE, HOTKEY_EDITOR_MAP_APPLY_MASK,
|
||||
HOTKEY_EDITOR_MAP_CREATE_MASK_TO,
|
||||
HOTKEY_EDITOR_REFRESH, HOTKEY_EDITOR_UPDATE_TRANSITIONS,
|
||||
HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS,
|
||||
HOTKEY_EDITOR_REFRESH_IMAGE_CACHE,
|
||||
|
|
Loading…
Add table
Reference in a new issue