The Battle for Wesnoth  1.13.4+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 - 2016 by Fabian Mueller <[email protected]>
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 #ifndef EDITOR_ACTION_ITEM_HPP
27 #define EDITOR_ACTION_ITEM_HPP
28 
29 #include "editor/action/action.hpp"
30 #include "overlay.hpp"
31 
32 //#include "item_types.hpp"
33 //#include "item.hpp"
34 
35 
36 namespace editor {
37 
38 
39 /**
40  * place a new item on the map
41  */
43 {
44  public:
46  const overlay& item)
47  : editor_action_location(loc), item_(item)
48  {
49  }
50  editor_action_item* clone() const;
51  editor_action* perform(map_context& mc) const;
52  void perform_without_undo(map_context& mc) const;
53  const char* get_name() const { return "item"; }
54  protected:
56 };
57 
58 /**
59  * Remove a item from the map.
60  */
62 {
63  public:
66  {
67  }
69  editor_action* perform(map_context& mc) const;
70  void perform_without_undo(map_context& mc) const;
71  const char* get_name() const { return "item_delete"; }
72 };
73 
75 {
76  public:
78  : editor_action_location(loc), new_loc_(new_loc)
79  {
80  }
82  editor_action* perform(map_context& mc) const;
83  void perform_without_undo(map_context& mc) const;
84  const char* get_name() const { return "item_replace"; }
85  protected:
87 };
88 
90 {
91  public:
93  : editor_action_location(loc), new_direction_(new_direction), old_direction_(old_direction)
94  {
95  }
97  editor_action* perform(map_context& mc) const;
98  void perform_without_undo(map_context& mc) const;
99  const char* get_name() const { return "item_facing"; }
100 protected:
103 };
104 
105 
106 } //end namespace editor
107 
108 #endif
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:43
place a new item on the map
Definition: action_item.hpp:42
editor_action_item(map_location loc, const overlay &item)
Definition: action_item.hpp:45
const char * get_name() const
Definition: action_item.hpp:84
editor_action_item * clone() const
Action cloning.
Definition: action_item.cpp:31
Base class for actions which act on a specified location (and possibly on other locations that can be...
Definition: action.hpp:177
editor_action_item_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
Definition: action_item.hpp:92
editor_action_item_replace * clone() const
Action cloning.
Definition: action_item.cpp:83
editor_action_item_delete(map_location loc)
Definition: action_item.hpp:64
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:88
editor_action_item_replace(map_location loc, map_location new_loc)
Definition: action_item.hpp:77
editor_action_item_facing * clone() const
Action cloning.
const char * get_name() const
Definition: action_item.hpp:53
map_location::DIRECTION new_direction_
const char * get_name() const
Definition: action_item.hpp:99
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:58
const char * get_name() const
Definition: action_item.hpp:71
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Editor action classes.
Remove a item from the map.
Definition: action_item.hpp:61
Manage the empty-palette in the editor.
Definition: action.cpp:28
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:96
map_location::DIRECTION old_direction_
Encapsulates the map of the game.
Definition: location.hpp:38
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:36
Base class for all editor actions.
Definition: action_base.hpp:41
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:40
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:41
editor_action_item_delete * clone() const
Action cloning.
Definition: action_item.cpp:53
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_item.cpp:72
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.