Skip to content
Browse files

Implement raise layer as an undoable action

  • Loading branch information...
1 parent 669b4f0 commit 1c594bf0bd1a7c6e2fafab80f3c0c8fd8d401034 @Kazade committed May 6, 2012
View
17 platformation/actions/layer_raise_action.cpp
@@ -0,0 +1,17 @@
+#include "layer_raise_action.h"
+
+LayerRaiseAction::LayerRaiseAction(Level* level, LayerID layer):
+ Action(level),
+ layer_id_(layer) {
+
+}
+
+void LayerRaiseAction::do_action() {
+ assert(level_);
+ level_->raise_layer(layer_id_);
+}
+
+void LayerRaiseAction::undo_action() {
+ assert(level_);
+ level_->lower_layer(layer_id_);
+}
View
18 platformation/actions/layer_raise_action.h
@@ -0,0 +1,18 @@
+#ifndef LAYER_RAISE_ACTION_H
+#define LAYER_RAISE_ACTION_H
+
+#include "action.h"
+#include "platformation/typedefs.h"
+
+class LayerRaiseAction : public Action {
+public:
+ LayerRaiseAction(Level* level, LayerID layer);
+ virtual void do_action();
+ virtual void undo_action();
+ virtual std::string get_description() { return "raise layer"; }
+
+private:
+ LayerID layer_id_;
+};
+
+#endif
View
7 platformation/layer_manager.cpp
@@ -25,6 +25,7 @@
#include "layer_manager.h"
#include "layer_rename_dialog.h"
#include "actions/layer_rename_action.h"
+#include "actions/layer_raise_action.h"
using boost::bind;
@@ -84,8 +85,9 @@ void LayerManager::on_layer_lower() {
}
void LayerManager::on_layer_raise() {
- level_->raise_layer(level_->active_layer_id());
- update_list_view();
+ Action::ptr raise_action(new LayerRaiseAction(level_, level_->active_layer_id()));
+ raise_action->do_action();
+ get_main_window()->get_action_manager().push_action(raise_action);
}
void LayerManager::on_layer_rename() {
@@ -124,6 +126,7 @@ void LayerManager::set_level(Level* level) {
if(level_) {
level_->layer_created().connect(bind(&LayerManager::on_layer_created, this, _1));
level_->layer_destroyed().connect(bind(&LayerManager::on_layer_destroyed, this, _1));
+ level_->layers_changed().connect(bind(&LayerManager::update_list_view, this));
level_->trigger_layer_created_on_all_layers();
}
View
4 platformation/level.cpp
@@ -145,6 +145,7 @@ LayerID Level::create_new_layer() {
//Call signal
signal_layer_created_(new_layer.get());
signal_changed_();
+ signal_layers_changed_();
//We want layer changes to trigger level changed signals
new_layer->signal_changed().connect(sigc::mem_fun(this, &Level::on_layer_changed));
@@ -181,6 +182,7 @@ void Level::destroy_layer(LayerID layer_id) {
signal_changed_();
signal_layer_destroyed_(NULL); //FIXME: Argument is useless
+ signal_layers_changed_();
}
uint32_t Level::layer_count() const {
@@ -206,6 +208,7 @@ void Level::lower_layer(LayerID layer_id) {
active_layer_ = layer(layer_by_index(i-1)).id();
signal_changed_();
+ signal_layers_changed_();
}
}
@@ -218,6 +221,7 @@ void Level::raise_layer(LayerID layer_id) {
active_layer_ = layer(layer_by_index(i+1)).id();
signal_changed_();
+ signal_layers_changed_();
}
}
View
6 platformation/level.h
@@ -95,6 +95,8 @@ class Level {
sigc::signal<void, Layer*>& layer_created() { return signal_layer_created_; }
sigc::signal<void, Layer*>& layer_destroyed() { return signal_layer_destroyed_; }
+ sigc::signal<void>& layers_changed() { return signal_layers_changed_; }
+
sigc::signal<void>& signal_changed() { return signal_changed_; }
sigc::signal<void>& signal_saved() { return signal_saved_; }
@@ -106,7 +108,7 @@ class Level {
//If a layer is changed, then the level is classed as altered
- void on_layer_changed() { signal_changed_(); }
+ void on_layer_changed() { signal_changed_(); signal_layers_changed_(); }
TileInstance* spawn_tile_instance(Tile::ptr tile) {
TileID id;
@@ -159,8 +161,10 @@ class Level {
sigc::signal<void> signal_changed_;
sigc::signal<void> signal_saved_;
+
sigc::signal<void, Layer*> signal_layer_created_;
sigc::signal<void, Layer*> signal_layer_destroyed_;
+ sigc::signal<void> signal_layers_changed_;
typedef std::vector<Layer::ptr> LayerArray;
LayerArray layers_;

0 comments on commit 1c594bf

Please sign in to comment.
Something went wrong with that request. Please try again.