allow animation level progressive parameters.
This should simplify backward compatibilty code greatly...
This commit is contained in:
parent
e21a0fec2d
commit
366f1b9b55
8 changed files with 137 additions and 32 deletions
|
@ -60,6 +60,8 @@ Version 1.3.9:
|
|||
* preserve aspect ratio of the minimap (FR/bug #9999)
|
||||
* the debug "Create unit" dialog have now two columns (race and type) and is
|
||||
correctly sorted.
|
||||
* progressive parameters can be specified both in [animation] and in
|
||||
[frame]
|
||||
* The linger mode "Next Scenario" button renamed to "End Scenario"
|
||||
* improved the display of the trait descriptions
|
||||
* multiplayer:
|
||||
|
|
|
@ -78,6 +78,7 @@ public:
|
|||
const T& get_first_frame() const;
|
||||
const T& get_last_frame() const;
|
||||
int get_frames_count() const;
|
||||
void force_change() {does_not_change_ = false ; }
|
||||
const bool does_not_change() const {return does_not_change_;}
|
||||
|
||||
static const T void_value_; //MSVC: the frame constructor below requires this to be public
|
||||
|
|
32
src/unit.cpp
32
src/unit.cpp
|
@ -1653,7 +1653,7 @@ const surface unit::still_image(bool scaled) const
|
|||
void unit::set_standing(const game_display &disp,const gamemap::location& loc, bool with_bars)
|
||||
{
|
||||
state_ = STATE_STANDING;
|
||||
start_animation(disp,loc,choose_animation(disp,loc,"standing"),with_bars);
|
||||
start_animation(disp,loc,choose_animation(disp,loc,"standing"),with_bars,true);
|
||||
}
|
||||
void unit::set_defending(const game_display &disp,const gamemap::location& loc, int damage,const attack_type* attack,const attack_type* secondary_attack,int swing_num)
|
||||
{
|
||||
|
@ -1768,7 +1768,7 @@ void unit::set_idling(const game_display &disp,const gamemap::location& loc)
|
|||
start_animation(disp,loc,choose_animation(disp,loc,"idling"),true);
|
||||
}
|
||||
|
||||
void unit::start_animation(const game_display &disp, const gamemap::location &loc,const unit_animation * animation,bool with_bars)
|
||||
void unit::start_animation(const game_display &disp, const gamemap::location &loc,const unit_animation * animation,bool with_bars,bool cycles)
|
||||
{
|
||||
if(!animation) {
|
||||
set_standing(disp,loc,with_bars);
|
||||
|
@ -1778,7 +1778,7 @@ void unit::start_animation(const game_display &disp, const gamemap::location &lo
|
|||
offset_=0;
|
||||
if(anim_) delete anim_;
|
||||
anim_ = new unit_animation(*animation);
|
||||
anim_->start_animation(anim_->get_begin_time(), false, disp.turbo_speed());
|
||||
anim_->start_animation(anim_->get_begin_time(), cycles, disp.turbo_speed());
|
||||
frame_begin_time_ = anim_->get_begin_time() -1;
|
||||
if (disp.idle_anim()) {
|
||||
next_idling_ = get_current_animation_tick()
|
||||
|
@ -1838,16 +1838,15 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
|
|||
if(!anim_) {
|
||||
set_standing(disp,loc);
|
||||
}
|
||||
const unit_frame& current_frame = anim_->get_current_frame();
|
||||
|
||||
if(frame_begin_time_ != anim_->get_current_frame_begin_time()) {
|
||||
frame_begin_time_ = anim_->get_current_frame_begin_time();
|
||||
if(!current_frame.sound().empty()) {
|
||||
sound::play_sound(current_frame.sound());
|
||||
if(!anim_->sound().empty()) {
|
||||
sound::play_sound(anim_->sound());
|
||||
}
|
||||
}
|
||||
|
||||
double tmp_offset = current_frame.offset(anim_->get_current_frame_time(),offset_);
|
||||
double tmp_offset = anim_->offset(offset_);
|
||||
int d2 = disp.hex_size() / 2;
|
||||
const int x = static_cast<int>(tmp_offset * xdst + (1.0-tmp_offset) * xsrc) + d2;
|
||||
const int y = static_cast<int>(tmp_offset * ydst + (1.0-tmp_offset) * ysrc) + d2 - height_adjust;
|
||||
|
@ -1864,19 +1863,18 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
|
|||
halo::remove(unit_anim_halo_);
|
||||
unit_anim_halo_ = halo::NO_HALO;
|
||||
}
|
||||
if(!current_frame.halo(anim_->get_current_frame_time()).empty()) {
|
||||
int ft = anim_->get_current_frame_time();
|
||||
int dx = static_cast<int>(current_frame.halo_x(ft) * disp.get_zoom_factor());
|
||||
int dy = static_cast<int>(current_frame.halo_y(ft) * disp.get_zoom_factor());
|
||||
if(!anim_->halo().empty()) {
|
||||
int dx = static_cast<int>(anim_->halo_x() * disp.get_zoom_factor());
|
||||
int dy = static_cast<int>(anim_->halo_y() * disp.get_zoom_factor());
|
||||
if (facing_west) dx = -dx;
|
||||
unit_anim_halo_ = halo::add(x + dx, y + dy,
|
||||
current_frame.halo(ft), gamemap::location(-1, -1),
|
||||
anim_->halo(), gamemap::location(-1, -1),
|
||||
facing_west ? halo::HREVERSE : halo::NORMAL);
|
||||
}
|
||||
|
||||
|
||||
image::locator image_loc;
|
||||
image_loc = current_frame.image();
|
||||
image_loc = anim_->image();
|
||||
if(image_loc.is_void()) {
|
||||
image_loc = absolute_image();
|
||||
}
|
||||
|
@ -1902,7 +1900,7 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
|
|||
|
||||
bool stoned = utils::string_bool(get_state("stoned"));
|
||||
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),current_frame.highlight_ratio(anim_->get_current_frame_time()));
|
||||
fixed_t highlight_ratio = minimum<fixed_t>(alpha(),anim_->highlight_ratio());
|
||||
if(invisible(loc,disp.get_units(),disp.get_teams()) &&
|
||||
highlight_ratio > ftofxp(0.5)) {
|
||||
highlight_ratio = ftofxp(0.5);
|
||||
|
@ -1911,8 +1909,8 @@ void unit::redraw_unit(game_display& disp, const gamemap::location& loc)
|
|||
highlight_ratio = ftofxp(1.5);
|
||||
}
|
||||
|
||||
Uint32 blend_with = current_frame.blend_with();
|
||||
double blend_ratio = current_frame.blend_ratio(anim_->get_current_frame_time());
|
||||
Uint32 blend_with = anim_->blend_with();
|
||||
double blend_ratio = anim_->blend_ratio();
|
||||
//if(blend_ratio == 0) { blend_with = disp.rgb(0,0,0); }
|
||||
if (utils::string_bool(get_state("poisoned")) && blend_ratio == 0){
|
||||
blend_with = disp.rgb(0,255,0);
|
||||
|
@ -2079,7 +2077,7 @@ std::set<gamemap::location> unit::overlaps(const gamemap::location &loc) const
|
|||
|
||||
// Very early calls, anim not initialized yet
|
||||
double tmp_offset=offset_;
|
||||
if(anim_)tmp_offset= anim_->get_current_frame().offset(anim_->get_animation_time(),offset_);
|
||||
if(anim_)tmp_offset= anim_->offset(offset_);
|
||||
|
||||
// Invalidate adjacent neighbours if we don't stay in our hex
|
||||
if(tmp_offset != 0) {
|
||||
|
|
|
@ -249,7 +249,7 @@ public:
|
|||
STATE_DYING, STATE_EXTRA, STATE_TELEPORT,
|
||||
STATE_RECRUITED, STATE_HEALED, STATE_POISONED,
|
||||
STATE_IDLEIN, STATE_IDLING, STATE_VICTORIOUS};
|
||||
void start_animation(const game_display &disp, const gamemap::location &loc,const unit_animation* animation, bool with_bars);
|
||||
void start_animation(const game_display &disp, const gamemap::location &loc,const unit_animation* animation, bool with_bars,bool cycles=false);
|
||||
|
||||
//! The name of the file to game_display (used in menus).
|
||||
const std::string& absolute_image() const { return cfg_["image"]; }
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
|
@ -76,7 +76,7 @@ config unit_animation::prepare_animation(const config &cfg,const std::string ani
|
|||
// copy the end of the anim "as is" other if will be treated later
|
||||
while(child != analyzed_anim.ordered_end()) {
|
||||
for(std::vector<config>::iterator itor= to_add.begin(); itor != to_add.end();itor++) {
|
||||
itor->add_child(*(*child).first,*(*child).second);
|
||||
itor->add_child(*(*child).first,*(*child).second);
|
||||
|
||||
}
|
||||
child++;
|
||||
|
@ -117,6 +117,23 @@ unit_animation::unit_animation(const config& cfg,const std::string frame_string
|
|||
unit_frame tmp_frame(**range.first);
|
||||
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
|
||||
}
|
||||
halo_ = progressive_string(cfg["halo"],get_animation_duration());
|
||||
halo_x_ = progressive_int(cfg["halo_x"],get_animation_duration());
|
||||
halo_y_ = progressive_int(cfg["halo_y"],get_animation_duration());
|
||||
std::vector<std::string> tmp_blend=utils::split(cfg["blend_color"]);
|
||||
if(tmp_blend.size() ==3) blend_with_= display::rgb(atoi(tmp_blend[0].c_str()),atoi(tmp_blend[1].c_str()),atoi(tmp_blend[2].c_str()));
|
||||
blend_ratio_ = progressive_double(cfg["blend_ratio"],get_animation_duration());
|
||||
highlight_ratio_ = progressive_double(cfg["alpha"],get_animation_duration());
|
||||
offset_ = progressive_double(cfg["offset"],get_animation_duration());
|
||||
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
!halo_y_.does_not_change() ||
|
||||
!blend_ratio_.does_not_change() ||
|
||||
!highlight_ratio_.does_not_change() ||
|
||||
!offset_.does_not_change() ) {
|
||||
force_change();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& my_directions = utils::split(cfg["direction"]);
|
||||
for(std::vector<std::string>::const_iterator i = my_directions.begin(); i != my_directions.end(); ++i) {
|
||||
|
@ -280,3 +297,53 @@ void unit_animation::back_compat_add_name(const std::string name,const std::stri
|
|||
primary_attack_filter_.push_back(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::string &unit_animation::halo(const std::string&default_val ) const
|
||||
{
|
||||
return get_current_frame().halo(get_current_frame_time(),halo_.get_current_element(get_animation_time(),default_val));
|
||||
}
|
||||
|
||||
int unit_animation::halo_x(const int default_val) const
|
||||
{
|
||||
return get_current_frame().halo_x(get_current_frame_time(),halo_x_.get_current_element(get_animation_time(),default_val));
|
||||
}
|
||||
int unit_animation::halo_y(const int default_val) const
|
||||
{
|
||||
return get_current_frame().halo_y(get_current_frame_time(),halo_y_.get_current_element(get_animation_time(),default_val));
|
||||
}
|
||||
Uint32 unit_animation::blend_with() const
|
||||
{
|
||||
#warning TBSL: "this should become a progressive param somehow..."
|
||||
return get_current_frame().blend_with();
|
||||
}
|
||||
double unit_animation::blend_ratio(const double default_val) const
|
||||
{
|
||||
return get_current_frame().blend_ratio(get_current_frame_time(),blend_ratio_.get_current_element(get_animation_time(),default_val));
|
||||
}
|
||||
|
||||
fixed_t unit_animation::highlight_ratio(const float default_val) const
|
||||
{
|
||||
return get_current_frame().highlight_ratio(get_current_frame_time(),highlight_ratio_.get_current_element(get_animation_time(),default_val));
|
||||
}
|
||||
|
||||
double unit_animation::offset(double default_val) const
|
||||
{
|
||||
return get_current_frame().offset(get_current_frame_time(),offset_.get_current_element(get_animation_time(),default_val)) ;
|
||||
}
|
||||
|
||||
bool unit_animation::need_update() const
|
||||
{
|
||||
if(animated<unit_frame>::need_update()) return true;
|
||||
if(get_current_frame().need_update()) return true;
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
!halo_y_.does_not_change() ||
|
||||
!blend_ratio_.does_not_change() ||
|
||||
!highlight_ratio_.does_not_change() ||
|
||||
!offset_.does_not_change() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,20 @@ class unit_animation:public animated<unit_frame>
|
|||
explicit unit_animation(int start_time,const unit_frame &frame,const std::string& even="",const int variation=0);
|
||||
int matches(const game_display &disp,const gamemap::location& loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int swing_num =0) const;
|
||||
|
||||
image::locator image() const { return get_current_frame().image() ; }
|
||||
image::locator image_diagonal() const { return get_current_frame().image_diagonal() ; }
|
||||
std::string sound() const { return get_current_frame().sound() ; };
|
||||
const std::string &halo(const std::string&default_val ="") const;
|
||||
int halo_x(const int default_val = 0) const;
|
||||
int halo_y(const int default_val = 0) const;
|
||||
//int duration() const { return get_current_frame().duration(); }
|
||||
Uint32 blend_with() const;
|
||||
double blend_ratio(const double default_val = 0) const;
|
||||
fixed_t highlight_ratio(const float default_val = 1.0) const;
|
||||
double offset(double default_val =0.0) const;
|
||||
|
||||
bool need_update() const;
|
||||
|
||||
// only to support all [attack_anim] format, to remove at 1.3.10 time
|
||||
void back_compat_add_name(const std::string name="",const std::string range ="");
|
||||
const animated<unit_frame> &get_missile_anim() const {return missile_anim_;}
|
||||
|
@ -58,6 +72,16 @@ class unit_animation:public animated<unit_frame>
|
|||
std::vector<hit_type> hits_;
|
||||
std::vector<int> swing_num_;
|
||||
animated<unit_frame> missile_anim_;
|
||||
// prevent people from using the current frame directly
|
||||
const unit_frame& get_current_frame() const { return animated<unit_frame>::get_current_frame(); }
|
||||
//animation params that can be locally overridden by frames
|
||||
progressive_string halo_;
|
||||
progressive_int halo_x_;
|
||||
progressive_int halo_y_;
|
||||
Uint32 blend_with_;
|
||||
progressive_double blend_ratio_;
|
||||
progressive_double highlight_ratio_;
|
||||
progressive_double offset_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ unit_frame::unit_frame() :
|
|||
image_(), image_diagonal_(),halo_(), sound_(),
|
||||
halo_x_(), halo_y_(), duration_(0),
|
||||
blend_with_(0),blend_ratio_(),
|
||||
highlight_ratio_("1.0"),offset_("")
|
||||
highlight_ratio_(""),offset_()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ unit_frame::unit_frame(const config& cfg)
|
|||
std::vector<std::string> tmp_blend=utils::split(cfg["blend_color"]);
|
||||
if(tmp_blend.size() ==3) blend_with_= display::rgb(atoi(tmp_blend[0].c_str()),atoi(tmp_blend[1].c_str()),atoi(tmp_blend[2].c_str()));
|
||||
blend_ratio_ = progressive_double(cfg["blend_ratio"],duration_);
|
||||
highlight_ratio_ = progressive_double(cfg["alpha"].empty()?"1.0":cfg["alpha"],duration_);
|
||||
highlight_ratio_ = progressive_double(cfg["alpha"],duration_);
|
||||
offset_ = progressive_double(cfg["offset"],duration_);
|
||||
|
||||
}
|
||||
|
@ -204,4 +204,16 @@ bool unit_frame::does_not_change() const
|
|||
highlight_ratio_.does_not_change() &&
|
||||
offset_.does_not_change();
|
||||
}
|
||||
bool unit_frame::need_update() const
|
||||
{
|
||||
if(!halo_.does_not_change() ||
|
||||
!halo_x_.does_not_change() ||
|
||||
!halo_y_.does_not_change() ||
|
||||
!blend_ratio_.does_not_change() ||
|
||||
!highlight_ratio_.does_not_change() ||
|
||||
!offset_.does_not_change() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,32 +64,33 @@ class unit_frame {
|
|||
// Constructors
|
||||
unit_frame();
|
||||
explicit unit_frame(const image::locator& image, int duration=0,
|
||||
const std::string& highlight="1.0",const std::string& offset="",
|
||||
Uint32 blend_color = 0, const std::string& blend_rate = "0",
|
||||
const std::string& highlight="",const std::string& offset="",
|
||||
Uint32 blend_color = 0, const std::string& blend_rate = "",
|
||||
const std::string & in_halo = "",
|
||||
const std::string & halox = "",const std::string & haloy = "",
|
||||
const image::locator & diag ="");
|
||||
explicit unit_frame(const config& cfg);
|
||||
image::locator image() const { return image_ ;}
|
||||
image::locator image_diagonal() const { return image_diagonal_ ; }
|
||||
const std::string &halo(int current_time) const
|
||||
{ return halo_.get_current_element(current_time); }
|
||||
const std::string &halo(int current_time,const std::string& default_val="") const
|
||||
{ return halo_.get_current_element(current_time,default_val); }
|
||||
|
||||
std::string sound() const { return sound_ ; };
|
||||
int halo_x(int current_time) const { return halo_x_.get_current_element(current_time); }
|
||||
int halo_y(int current_time) const { return halo_y_.get_current_element(current_time); }
|
||||
int halo_x(int current_time,const int default_val=0) const { return halo_x_.get_current_element(current_time,default_val); }
|
||||
int halo_y(int current_time,const int default_val=0) const { return halo_y_.get_current_element(current_time,default_val); }
|
||||
int duration() const { return duration_; }
|
||||
Uint32 blend_with() const { return blend_with_; }
|
||||
double blend_ratio(int current_time) const
|
||||
{ return blend_ratio_.get_current_element(current_time); }
|
||||
double blend_ratio(int current_time,const fixed_t default_val=0.0) const
|
||||
{ return blend_ratio_.get_current_element(current_time,default_val); }
|
||||
|
||||
fixed_t highlight_ratio(int current_time) const
|
||||
{ return ftofxp(highlight_ratio_.get_current_element(current_time)); }
|
||||
fixed_t highlight_ratio(int current_time,double default_val =0.0) const
|
||||
{ return ftofxp(highlight_ratio_.get_current_element(current_time,default_val)); }
|
||||
|
||||
double offset(int current_time,double default_val =0.0) const
|
||||
{ return offset_.get_current_element(current_time,default_val) ; }
|
||||
|
||||
bool does_not_change() const;
|
||||
bool need_update() const;
|
||||
private:
|
||||
image::locator image_;
|
||||
image::locator image_diagonal_;
|
||||
|
|
Loading…
Add table
Reference in a new issue