(change-on-touch #t)
(stay-action "")
(initial-stay-action #f)
+ (stay-group "world2-boat")
(x 38)
(y 21)
(sprite "images/worldmap/common/boat/boat.sprite")
(change-on-touch #f)
(stay-action "empty")
(initial-stay-action #t)
+ (stay-group "world2-boat")
(x 34)
(y 15)
(sprite "images/worldmap/common/boat/boat.sprite")
(sprite-change
(change-on-touch #f)
(stay-action "empty")
- (initial-stay-action #f)
+ (initial-stay-action #t)
+ (stay-group "world1-boat")
(x 19)
(y 42)
(sprite "images/worldmap/common/boat/boat.sprite")
(change-on-touch #t)
(stay-action "")
(initial-stay-action #f)
+ (stay-group "world1-boat")
(x 10)
(y 45)
(sprite "images/worldmap/common/boat/boat.sprite")
lisp->get("stay-action", stay_action);
lisp->get("initial-stay-action", in_stay_action);
+
+ lisp->get("stay-group", stay_group);
+
+ all_sprite_changes.push_back(this);
}
SpriteChange::~SpriteChange()
{
+ all_sprite_changes.remove(this);
}
void
{
}
+void
+SpriteChange::set_stay_action()
+{
+ in_stay_action = true;
+}
+
+void
+SpriteChange::clear_stay_action()
+{
+ in_stay_action = false;
+
+ // if we are in a stay_group, also clear all stay actions in this group
+ if (stay_group != "") {
+ for (std::list<SpriteChange*>::iterator i = all_sprite_changes.begin(); i != all_sprite_changes.end(); i++) {
+ SpriteChange* sc = *i;
+ if (sc->stay_group != stay_group) continue;
+ sc->in_stay_action = false;
+ }
+ }
+}
+
+std::list<SpriteChange*> SpriteChange::all_sprite_changes;
+
}
#include <string>
#include <memory>
+#include <list>
#include "game_object.hpp"
#include "lisp/lisp.hpp"
#include "math/vector.hpp"
* another SpriteChange object.
*/
std::string stay_action;
+
/**
- * should the stayaction be displayed
+ * name of a group in which only one SpriteChange will ever have its stay_action displayed.
+ * Leave empty if you don't care.
*/
- bool in_stay_action;
+ std::string stay_group;
virtual void draw(DrawingContext& context);
virtual void update(float elapsed_time);
+
+ /**
+ * Activates the SpriteChange's stay action, if applicable
+ */
+ void set_stay_action();
+
+ /**
+ * Deactivates the SpriteChange's stay action, if applicable
+ */
+ void clear_stay_action();
+
+private:
+ /**
+ * should the stayaction be displayed
+ */
+ bool in_stay_action;
+
+ static std::list<SpriteChange*> all_sprite_changes;
+
};
}
SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos);
if(sprite_change != NULL) {
sprite.reset(new Sprite( *(sprite_change->sprite.get()) ));
- sprite_change->in_stay_action = false;
+ sprite_change->clear_stay_action();
}
// if this is a special_tile with passive_message, display it
SpriteChange* next_sprite = worldmap->at_sprite_change(next_tile);
if(next_sprite != NULL && next_sprite->change_on_touch) {
sprite.reset(new Sprite( *(next_sprite->sprite.get()) ));
- next_sprite->in_stay_action = false;
+ next_sprite->clear_stay_action();
}
SpriteChange* last_sprite = worldmap->at_sprite_change(tile_pos);
if(last_sprite != NULL && next_sprite != NULL) {
log_debug << "Old: " << tile_pos << " New: " << next_tile << std::endl;
- last_sprite->in_stay_action = true;
+ last_sprite->set_stay_action();
}
tile_pos = next_tile;
SpriteChange* sprite_change = worldmap->at_sprite_change(tile_pos);
if(sprite_change != NULL) {
sprite.reset(new Sprite( *(sprite_change->sprite.get()) ));
- sprite_change->in_stay_action = false;
+ sprite_change->clear_stay_action();
}
}