4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file camera_toggle.cpp
26
* \brief Implementation of the bear::camera_toggle class.
27
* \author Julien Jorge
29
#include "generic_items/camera_toggle.hpp"
31
#include "engine/level.hpp"
32
#include "generic_items/camera.hpp"
34
BASE_ITEM_EXPORT( camera_toggle, bear )
36
/*----------------------------------------------------------------------------*/
40
bear::camera_toggle::camera_toggle()
41
: m_starting_smooth_delay(0), m_ending_smooth_delay(0), m_camera(NULL)
43
set_can_move_items(false);
46
} // camera_toggle::camera_toggle()
48
/*----------------------------------------------------------------------------*/
50
* \brief Set a field of type \c <item>.
51
* \param name The name of the field.
52
* \param value The new value of the field.
53
* \return false if the field "name" is unknow, true otherwise.
55
bool bear::camera_toggle::set_item_field
56
( const std::string& name, engine::base_item* value )
60
if (name == "camera_toggle.camera")
63
ok = super::set_item_field(name, value);
66
} // camera_toggle::set_item_field()
68
/*----------------------------------------------------------------------------*/
70
* \brief Set a field of type \c <real>.
71
* \param name The name of the field.
72
* \param value The new value of the field.
73
* \return false if the field "name" is unknow, true otherwise.
75
bool bear::camera_toggle::set_real_field
76
( const std::string& name, double value )
80
if (name == "camera_toggle.starting_transition_duration")
81
m_starting_smooth_delay = value;
82
else if (name == "camera_toggle.ending_transition_duration")
83
m_ending_smooth_delay = value;
85
ok = super::set_real_field(name,value);
88
} // camera_toggle::set_real_field()
90
/*----------------------------------------------------------------------------*/
92
* \brief Tell if the item is well initialized.
94
bool bear::camera_toggle::is_valid() const
96
// We allow the camera to be NULL only if the toggle has been toggled on, in
97
// which case he can have taken the NULL camera of the level.
98
return ((m_camera != (camera*)NULL) || is_on() )
99
&& (m_starting_smooth_delay >= 0)
100
&& (m_ending_smooth_delay >= 0) && super::is_valid();
101
} // camera_toggle::is_valid()
103
/*----------------------------------------------------------------------------*/
105
* \brief Initialise the item in its off state.
107
void bear::camera_toggle::build_off()
110
} // camera_toggle::build_off()
112
/*----------------------------------------------------------------------------*/
114
* \brief Activate the camera.
115
* \param activator (ignored) The item that activates the toggle, if any.
117
void bear::camera_toggle::on_toggle_on( engine::base_item* activator )
120
} // camera_toggle::on_toggle_on()
122
/*----------------------------------------------------------------------------*/
124
* \brief Restore the old camera.
125
* \param activator (ignored) The item that activates the toggle, if any.
127
void bear::camera_toggle::on_toggle_off( engine::base_item* activator )
130
} // camera_toggle::on_toggle_off()
132
/*----------------------------------------------------------------------------*/
134
* \brief Switch the camera of the level.
136
void bear::camera_toggle::switch_camera()
138
handle_type old_cam = get_level().get_camera();
140
if ( m_camera != (camera*)NULL )
144
if (m_starting_smooth_delay == 0)
145
m_camera->activate();
147
m_camera->smooth_activate(m_starting_smooth_delay);
151
if (m_ending_smooth_delay == 0)
152
m_camera->activate();
154
m_camera->smooth_activate(m_ending_smooth_delay);
159
} // camera_toggle::switch_camera()