The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_item.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Editor action classes. Some important points:
18  * - This is a polymorphic hierarchy of classes, so actions are usually passed around
19  * as editor_action pointers
20  * - The pointers can, in general, be null. Always check for null before doing anything.
21  * The helper functions perform_ that take a pointer do that.
22  * - The perform() functions can throw when an error occurs. Use smart pointers if you
23  * need to ensure the pointer is deleted.
24  */
25 
26 #pragma once
27 
28 #include "editor/action/action.hpp"
29 #include "overlay.hpp"
30 
31 //#include "item_types.hpp"
32 //#include "item.hpp"
33 
34 namespace editor
35 {
36 /**
37  * place a new item on the map
38  */
40 {
41 public:
44  , item_(item)
45  {
46  }
47 
48  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
49  editor_action_item* clone() const;
50 
51  editor_action* perform(map_context& mc) const;
52 
53  void perform_without_undo(map_context& mc) const;
54 
55  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
56  const std::string& get_name() const;
57 
58 protected:
60 };
61 
62 /**
63  * Remove a item from the map.
64  */
66 {
67 public:
70  {
71  }
72 
73  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
75 
76  editor_action* perform(map_context& mc) const;
77 
78  void perform_without_undo(map_context& mc) const;
79 
80  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
81  const std::string& get_name() const;
82 };
83 
85 {
86 public:
89  , new_loc_(new_loc)
90  {
91  }
92 
93  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
95 
96  editor_action* perform(map_context& mc) const;
97 
98  void perform_without_undo(map_context& mc) const;
99 
100  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
101  const std::string& get_name() const;
102 
103 protected:
105 };
106 
108 {
109 public:
111  map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
113  , new_direction_(new_direction)
114  , old_direction_(old_direction)
115  {
116  }
117 
118  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
120 
121  editor_action* perform(map_context& mc) const;
122 
123  void perform_without_undo(map_context& mc) const;
124 
125  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
126  const std::string& get_name() const;
127 
128 protected:
131 };
132 
133 } // end namespace editor
editor_action_item_facing * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:38
place a new item on the map
Definition: action_item.hpp:39
editor_action_item_delete * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
std::vector< char_t > string
editor_action_item(map_location loc, const overlay &item)
Definition: action_item.hpp:42
Base class for actions which act on a specified location (and possibly on other locations that can be...
Definition: action.hpp:189
editor_action_item_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
editor_action_item_delete(map_location loc)
Definition: action_item.hpp:68
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_item.cpp:74
editor_action_item_replace(map_location loc, map_location new_loc)
Definition: action_item.hpp:87
map_location::DIRECTION new_direction_
editor_action_item_replace * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_item.cpp:48
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
Editor action classes.
Remove a item from the map.
Definition: action_item.hpp:65
Manage the empty-palette in the editor.
Definition: action.cpp:29
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:82
map_location::DIRECTION old_direction_
Encapsulates the map of the game.
Definition: location.hpp:40
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_item.cpp:31
Base class for all editor actions.
Definition: action_base.hpp:40
editor_action_item * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:42
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:62
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.