The Battle for Wesnoth  1.19.7+dev
action_select.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Fabian Mueller <fabianmueller5@gmx.de>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Editor action classes. Some important points:
19  * - This is a polymorphic hierarchy of classes, so actions are usually passed around
20  * as editor_action pointers
21  * - The pointers can, in general, be null. Always check for null before doing anything.
22  * The helper functions perform_ that take a pointer do that.
23  * - The perform() functions can throw when an error occurs. Use smart pointers if you
24  * need to ensure the pointer is deleted.
25  */
26 
27 #pragma once
28 
29 #include "editor/action/action.hpp"
30 
31 namespace editor
32 {
33 /**
34  * Select the given locations
35  */
37 {
38 public:
39  editor_action_select(const std::set<map_location>& area)
40  : editor_action_area(area)
41  {
42  }
43 
44  std::unique_ptr<editor_action> clone() const override;
45  void extend(const editor_map& map, const std::set<map_location>& locs) override;
46  std::unique_ptr<editor_action> perform(map_context& mc) const override;
47  void perform_without_undo(map_context& mc) const override;
48  const std::string& get_name() const override;
49 };
50 
51 /**
52  * Deselect the given locations
53  */
55 {
56 public:
57  editor_action_deselect(const std::set<map_location>& area)
58  : editor_action_area(area)
59  {
60  }
61 
62  std::unique_ptr<editor_action> clone() const override;
63  void extend(const editor_map& map, const std::set<map_location>& locs) override;
64  std::unique_ptr<editor_action> perform(map_context& mc) const override;
65  void perform_without_undo(map_context& mc) const override;
66  const std::string& get_name() const override;
67 };
68 
69 /**
70  * Select the entire map
71  */
73 {
74 public:
76  {
77  }
78 
79  std::unique_ptr<editor_action> clone() const override;
80  std::unique_ptr<editor_action> perform(map_context& mc) const override;
81  void perform_without_undo(map_context& mc) const override;
82  const std::string& get_name() const override;
83 };
84 
85 /**
86  * Clear selection
87  */
89 {
90 public:
92  {
93  }
94 
95  std::unique_ptr<editor_action> clone() const override;
96  std::unique_ptr<editor_action> perform(map_context& mc) const override;
97  void perform_without_undo(map_context& mc) const override;
98  const std::string& get_name() const override;
99 };
100 
101 /**
102  * Invert the selection
103  */
105 {
106 public:
108  {
109  }
110 
111  std::unique_ptr<editor_action> clone() const override;
112  std::unique_ptr<editor_action> perform(map_context& mc) const override;
113  void perform_without_undo(map_context& mc) const override;
114  const std::string& get_name() const override;
115 };
116 
117 } // end namespace editor
Base class for area-affecting actions.
Definition: action.hpp:220
Deselect the given locations.
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void extend(const editor_map &map, const std::set< map_location > &locs) override
The crux of the extendable contract.
std::unique_ptr< editor_action > clone() const override
Action cloning.
const std::string & get_name() const override
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
editor_action_deselect(const std::set< map_location > &area)
const std::string & get_name() const override
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
std::unique_ptr< editor_action > clone() const override
Action cloning.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
const std::string & get_name() const override
std::unique_ptr< editor_action > clone() const override
Action cloning.
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
const std::string & get_name() const override
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
std::unique_ptr< editor_action > clone() const override
Action cloning.
Select the given locations.
void extend(const editor_map &map, const std::set< map_location > &locs) override
The crux of the extendable contract.
editor_action_select(const std::set< map_location > &area)
const std::string & get_name() const override
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
std::unique_ptr< editor_action > clone() const override
Action cloning.
Base class for all editor actions.
Definition: action_base.hpp:42
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
This class wraps around a map to provide a concise interface for the editor to work with.
Definition: map_context.hpp:63
Editor action classes.
Manage the empty-palette in the editor.
Definition: action.cpp:31