2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "util/reader.hpp"
21 #include "video/drawing_context.hpp"
22 #include "worldmap/sprite_change.hpp"
26 SpriteChange::SpriteChange(const Reader& lisp) :
28 change_on_touch(false),
36 lisp.get("change-on-touch", change_on_touch);
38 std::string spritefile = "";
39 lisp.get("sprite", spritefile);
40 sprite = sprite_manager->create(spritefile);
42 lisp.get("stay-action", stay_action);
43 lisp.get("initial-stay-action", in_stay_action);
45 lisp.get("stay-group", stay_group);
47 all_sprite_changes.push_back(this);
50 SpriteChange::~SpriteChange()
52 all_sprite_changes.remove(this);
56 SpriteChange::draw(DrawingContext& context)
58 if(in_stay_action && stay_action != "") {
59 sprite->set_action(stay_action);
60 sprite->draw(context, pos * 32, LAYER_OBJECTS-1);
65 SpriteChange::update(float )
70 SpriteChange::set_stay_action()
72 in_stay_action = true;
76 SpriteChange::clear_stay_action()
78 in_stay_action = false;
80 // if we are in a stay_group, also clear all stay actions in this group
81 if (stay_group != "") {
82 for (std::list<SpriteChange*>::iterator i = all_sprite_changes.begin(); i != all_sprite_changes.end(); i++) {
83 SpriteChange* sc = *i;
84 if (sc->stay_group != stay_group) continue;
85 sc->in_stay_action = false;
90 std::list<SpriteChange*> SpriteChange::all_sprite_changes;