Editor: Moved the clipboard actions to a context menu...

...available in paste mode. Added a terrain sampler feature --
ctrl+click when in paint or fill mode
This commit is contained in:
Tomasz Śniatowski 2009-04-14 12:14:52 +01:00
parent b03e2556d4
commit 83ea299518
6 changed files with 101 additions and 27 deletions

View file

@ -36,6 +36,8 @@ Version 1.7.0-svn:
* Added ability to load maps referenced in scenario files
* Added ability to work with maps embedded in scenario files (saving works
in a limited scope)
* Moved the clipboard actions to a context menu available in paste mode
* Added a terrain sampler feature -- ctrl+click when in paint or fill mode
* FormulaAI:
* Fixed bug #13230: added debug_float FormulaAI function to allow debugging
via floating popups on the specified hex

View file

@ -4,13 +4,13 @@
[editor_tool_hint]
# wmllint: local spelling left/right
id="editor-tool-paint"
text= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only."
text= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
[/editor_tool_hint]
[editor_tool_hint]
# wmllint: local spelling fore-/background
id="editor-tool-fill"
text= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only."
text= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
[/editor_tool_hint]
[editor_tool_hint]

View file

@ -130,7 +130,7 @@
id=menu-editor-edit
title= _ "Edit"
image=lite
items=undo,redo,editor-cut,editor-copy,editor-paste,editor-export-selection-coords,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-export-selection-coords,editor-select-all,editor-select-inverse,editor-select-none, editor-selection-fill,editor-selection-rotate,editor-selection-flip, editor-selection-generate,editor-selection-randomize
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed
@ -157,9 +157,9 @@
[/menu]
[menu]
id=menu-editor-selection
id=menu-editor-paste-context
is_context_menu=true
items=menu-editor-starting-position,undo,redo,editor-cut,editor-copy,editor-paste,editor-selection-fill,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
items=editor-paste,editor-clipboard-rotate-cw,editor-clipboard-rotate-ccw,editor-clipboard-flip-horizontal,editor-clipboard-flip-vertical
[/menu]
[mini_map]
@ -176,7 +176,7 @@
image=draw_button_editor
items=editor-tool-paint
# wmllint: local spelling left/right
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only."
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
tooltip_name_prepend=yes
ref=top-right-panel
#harcoded since the brushes are above, which are hardcoded in src/editor/editor_layout.cpp
@ -189,7 +189,7 @@
image=flood_button_editor
items=editor-tool-fill
# wmllint: local spelling fore-/background
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only."
tooltip= _ "Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor."
tooltip_name_prepend=yes
rect="+6,=,+24,+24"
xanchor=right

View file

@ -423,7 +423,8 @@ void editor_controller::load_map_dialog(bool force_same_context /* = false */)
}
int res = dialogs::show_file_chooser_dialog(gui(), fn, _("Choose a Map to Open"));
if (res == 0) {
load_map(fn, force_same_context ? false : use_mdi_); }
load_map(fn, force_same_context ? false : use_mdi_);
}
}
void editor_controller::new_map_dialog()
@ -1333,7 +1334,7 @@ bool editor_controller::allow_mouse_wheel_scroll(int x, int y)
bool editor_controller::right_click_show_menu(int /*x*/, int /*y*/, const bool /*browse*/)
{
return false;
return get_mouse_action()->has_context_menu();
}
bool editor_controller::left_click(int x, int y, const bool browse)
@ -1346,6 +1347,7 @@ bool editor_controller::left_click(int x, int y, const bool browse)
LOG_ED << "Left click action " << hex_clicked.x << " " << hex_clicked.y << "\n";
editor_action* a = get_mouse_action()->click_left(*gui_, x, y);
perform_refresh_delete(a, true);
palette_->draw(true);
return false;
}
@ -1373,6 +1375,7 @@ bool editor_controller::right_click(int x, int y, const bool browse)
LOG_ED << "Right click action " << hex_clicked.x << " " << hex_clicked.y << "\n";
editor_action* a = get_mouse_action()->click_right(*gui_, x, y);
perform_refresh_delete(a, true);
palette_->draw(true);
return false;
}

View file

@ -23,6 +23,11 @@
namespace editor2 {
bool mouse_action::has_context_menu() const
{
return false;
}
void mouse_action::move(editor_display& disp, const map_location& hex)
{
if (hex != previous_move_hex_) {
@ -132,6 +137,15 @@ bool mouse_action::has_shift_modifier() const
return key_[SDLK_RSHIFT] || key_[SDLK_LSHIFT];
}
bool mouse_action::has_ctrl_modifier() const
{
#ifdef __APPLE__
return key_[SDLK_RMETA] || key_[SDLK_LMETA];
#else
return key_[SDLK_RCTRL] || key_[SDLK_LCTRL];
#endif
}
void mouse_action::set_terrain_mouse_overlay(editor_display& disp, t_translation::t_terrain fg,
t_translation::t_terrain bg)
{
@ -249,15 +263,39 @@ const brush& brush_drag_mouse_action::get_brush()
}
editor_action* mouse_action_paint::click_perform_left(
editor_display& /*disp*/, const std::set<map_location>& hexes)
editor_action* mouse_action_paint::click_left(editor_display& disp, int x, int y)
{
if (has_ctrl_modifier()) {
map_location hex = disp.hex_clicked_on(x, y);
terrain_left_ = disp.map().get_terrain(hex);
return NULL;
} else {
return brush_drag_mouse_action::click_left(disp, x, y);
}
}
editor_action* mouse_action_paint::click_right(editor_display& disp, int x, int y)
{
if (has_ctrl_modifier()) {
map_location hex = disp.hex_clicked_on(x, y);
terrain_right_ = disp.map().get_terrain(hex);
return NULL;
} else {
return brush_drag_mouse_action::click_right(disp, x, y);
}
}
editor_action* mouse_action_paint::click_perform_left(
editor_display& disp, const std::set<map_location>& hexes)
{
if (has_ctrl_modifier()) return NULL;
return new editor_action_chain(new editor_action_paint_area(hexes, terrain_left_, has_shift_modifier()));
}
editor_action* mouse_action_paint::click_perform_right(
editor_display& /*disp*/, const std::set<map_location>& hexes)
{
if (has_ctrl_modifier()) return NULL;
return new editor_action_chain(new editor_action_paint_area(hexes, terrain_right_, has_shift_modifier()));
}
@ -315,6 +353,11 @@ void mouse_action_select::set_mouse_overlay(editor_display& disp)
}
bool mouse_action_paste::has_context_menu() const
{
return true;
}
std::set<map_location> mouse_action_paste::affected_hexes(
editor_display& /*disp*/, const map_location& hex)
{
@ -348,19 +391,30 @@ std::set<map_location> mouse_action_fill::affected_hexes(
editor_action* mouse_action_fill::click_left(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
//TODO only take the base terrain into account when searching for contigious terrain when painting base only
//or use a different key modifier for that
editor_action_fill* a = new editor_action_fill(hex, terrain_left_, has_shift_modifier());
return a;
if (has_ctrl_modifier()) {
terrain_left_ = disp.map().get_terrain(hex);
return NULL;
} else {
//TODO only take the base terrain into account when searching for contigious terrain when painting base only
//or use a different key modifier for that
editor_action_fill* a = new editor_action_fill(hex, terrain_left_, has_shift_modifier());
return a;
}
}
editor_action* mouse_action_fill::click_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
//TODO only take the base terrain into account when searching for contigious terrain when painting base only
//or use a different key modifier for that
editor_action_fill* a = new editor_action_fill(hex, terrain_right_, has_shift_modifier());
return a;
if (has_ctrl_modifier()) {
map_location hex = disp.hex_clicked_on(x, y);
terrain_right_ = disp.map().get_terrain(hex);
return NULL;
} else {
//TODO only take the base terrain into account when searching for contigious terrain when painting base only
//or use a different key modifier for that
editor_action_fill* a = new editor_action_fill(hex, terrain_right_, has_shift_modifier());
return a;
}
}
void mouse_action_fill::set_mouse_overlay(editor_display& disp)

View file

@ -43,6 +43,8 @@ public:
virtual ~mouse_action() {}
virtual bool has_context_menu() const;
/**
* Mouse move (not a drag). Never changes anything (other than temporary highlihts and similar)
*/
@ -114,6 +116,7 @@ public:
protected:
bool has_alt_modifier() const;
bool has_shift_modifier() const;
bool has_ctrl_modifier() const;
/**
* Helper function for derived classes that need a active-terrain mouse overlay
@ -228,8 +231,8 @@ private:
class mouse_action_paint : public brush_drag_mouse_action
{
public:
mouse_action_paint(const t_translation::t_terrain& terrain_left,
const t_translation::t_terrain& terrain_right,
mouse_action_paint(t_translation::t_terrain& terrain_left,
t_translation::t_terrain& terrain_right,
const brush* const * const brush, const CKey& key)
: brush_drag_mouse_action(brush, key)
, terrain_left_(terrain_left)
@ -237,6 +240,16 @@ public:
{
}
/**
* Handle terrain sampling before calling generic handler
*/
editor_action* click_left(editor_display& disp, int x, int y);
/**
* Handle terrain sampling before calling generic handler
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Create an appropriate editor_action and return it
*/
@ -250,8 +263,8 @@ public:
void set_mouse_overlay(editor_display& disp);
protected:
const t_translation::t_terrain& terrain_left_;
const t_translation::t_terrain& terrain_right_;
t_translation::t_terrain& terrain_left_;
t_translation::t_terrain& terrain_right_;
};
/**
@ -299,6 +312,8 @@ public:
{
}
bool has_context_menu() const;
/**
* Show an outline of where the paste will go
*/
@ -329,8 +344,8 @@ protected:
class mouse_action_fill : public mouse_action
{
public:
mouse_action_fill(const t_translation::t_terrain& terrain_left,
const t_translation::t_terrain& terrain_right, const CKey& key)
mouse_action_fill(t_translation::t_terrain& terrain_left,
t_translation::t_terrain& terrain_right, const CKey& key)
: mouse_action(key)
, terrain_left_(terrain_left)
, terrain_right_(terrain_right)
@ -355,8 +370,8 @@ public:
virtual void set_mouse_overlay(editor_display& disp);
protected:
const t_translation::t_terrain& terrain_left_;
const t_translation::t_terrain& terrain_right_;
t_translation::t_terrain& terrain_left_;
t_translation::t_terrain& terrain_right_;
};
/**