00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UNIT_FRAME_H_INCLUDED
00021 #define UNIT_FRAME_H_INCLUDED
00022
00023 #include "map.hpp"
00024 #include "util.hpp"
00025 #include "image.hpp"
00026 #include "serialization/string_utils.hpp"
00027 #include "game_display.hpp"
00028
00029 class config;
00030
00031 #include <string>
00032 #include <vector>
00033
00034 class progressive_string {
00035 public:
00036 progressive_string(const std::string& data = "",int duration = 0);
00037 int duration() const;
00038 const std::string & get_current_element(int time) const;
00039 bool does_not_change() const { return data_.size() <= 1; }
00040 std::string get_original(){return input_;}
00041 private:
00042 std::vector<std::pair<std::string,int> > data_;
00043 std::string input_;
00044 };
00045
00046 template <class T>
00047 class progressive_
00048 {
00049 std::vector<std::pair<std::pair<T, T>, int> > data_;
00050 std::string input_;
00051 public:
00052 progressive_(const std::string& data = "", int duration = 0);
00053 int duration() const;
00054 const T get_current_element(int time,T default_val=0) const;
00055 bool does_not_change() const;
00056 std::string get_original(){return input_;}
00057 };
00058
00059 typedef progressive_<int> progressive_int;
00060 typedef progressive_<double> progressive_double;
00061
00062 #endif
00063
00064 #ifndef UNIT_FRAME_H_PART2
00065 #define UNIT_FRAME_H_PART2
00066
00067 class frame_parameters{
00068 public:
00069 frame_parameters():
00070 image(""),
00071 image_diagonal(""),
00072 image_mod(""),
00073 halo(""),
00074 halo_x(0),
00075 halo_y(0),
00076 sound(""),
00077 text(""),
00078 text_color(0),
00079 duration(0),
00080 blend_with(0),
00081 blend_ratio(0.0),
00082 highlight_ratio(1.0),
00083 offset(0),
00084 submerge(0.0),
00085 x(0),
00086 y(0)
00087 {};
00088
00089 image::locator image;
00090 image::locator image_diagonal;
00091 std::string image_mod;
00092 std::string halo;
00093 int halo_x;
00094 int halo_y;
00095 std::string sound;
00096 std::string text;
00097 Uint32 text_color;
00098 int duration;
00099 Uint32 blend_with;
00100 double blend_ratio;
00101 double highlight_ratio;
00102 double offset;
00103 double submerge;
00104 int x;
00105 int y;
00106 } ;
00107
00108
00109
00110
00111 class frame_builder {
00112 public:
00113
00114 frame_builder():
00115 image_(image::locator()),
00116 image_diagonal_(image::locator()),
00117 image_mod_(""),
00118 halo_(""),
00119 halo_x_(""),
00120 halo_y_(""),
00121 sound_(""),
00122 text_(""),
00123 text_color_(0),
00124 duration_(1),
00125 blend_with_(0),
00126 blend_ratio_(""),
00127 highlight_ratio_(""),
00128 offset_(""),
00129 submerge_(""),
00130 x_(""),
00131 y_("")
00132 {};
00133 frame_builder(const config& cfg,const std::string &frame_string = "");
00134
00135 frame_builder & image(const image::locator image ,const std::string & image_mod="");
00136 frame_builder & image_diagonal(const image::locator image_diagonal,const std::string & image_mod="");
00137 frame_builder & sound(const std::string& sound);
00138 frame_builder & text(const std::string& text,const Uint32 text_color);
00139 frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y);
00140 frame_builder & duration(const int duration);
00141 frame_builder & blend(const std::string& blend_ratio,const Uint32 blend_color);
00142 frame_builder & highlight(const std::string& highlight);
00143 frame_builder & offset(const std::string& offset);
00144 frame_builder & submerge(const std::string& submerge);
00145 frame_builder & x(const std::string& x);
00146 frame_builder & y(const std::string& y);
00147
00148 const frame_parameters parameters(int current_time) const ;
00149
00150 int duration() const{ return duration_;};
00151 void recalculate_duration();
00152 bool does_not_change() const;
00153 bool need_update() const;
00154 private:
00155 image::locator image_;
00156 image::locator image_diagonal_;
00157 std::string image_mod_;
00158 progressive_string halo_;
00159 progressive_int halo_x_;
00160 progressive_int halo_y_;
00161 std::string sound_;
00162 std::string text_;
00163 Uint32 text_color_;
00164 int duration_;
00165 Uint32 blend_with_;
00166 progressive_double blend_ratio_;
00167 progressive_double highlight_ratio_;
00168 progressive_double offset_;
00169 progressive_double submerge_;
00170 progressive_int x_;
00171 progressive_int y_;
00172
00173 };
00174
00175
00176 class unit_frame {
00177 public:
00178
00179 unit_frame(const frame_builder builder=frame_builder()):builder_(builder){};
00180 void redraw(const int frame_time,bool first_time,const gamemap::location & src,const gamemap::location & dst,int*halo_id,const frame_parameters & animation_val,const frame_parameters & engine_val)const;
00181 const frame_parameters merge_parameters(int current_time,const frame_parameters & animation_val,const frame_parameters & engine_val=frame_parameters(),bool primary=false) const;
00182 const frame_parameters parameters(int current_time) const {return builder_.parameters(current_time);};
00183
00184 int duration() const { return builder_.duration();};
00185 bool does_not_change() const{ return builder_.does_not_change();};
00186 bool need_update() const{ return builder_.need_update();};
00187 void invalidate(const int frame_time,const gamemap::location & src,const gamemap::location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val,const bool primary) const;
00188 private:
00189 frame_builder builder_;
00190
00191 };
00192
00193 #endif