00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "HUD-Element.hpp"
00019 #include "UpdateFrame.hpp"
00020
00021 #include <log4cxx/logger.h>
00022
00023
00024 #include <libintl.h>
00025 #define _(string) gettext(string)
00026
00027
00028
00029 void AHUDElement::SetPosition(int X, int Y)
00030 {
00031 m_X = X;
00032 m_Y = Y;
00033 }
00034
00035 void AHUDElement::SetSize(int Width, int Height)
00036 {
00037 m_Height = Height;
00038 m_Width = Width;
00039 }
00040
00041
00042
00043 void AHUDPoll::init(float maxValue, const float *aktuell)
00044 {
00045 m_fAktuell = aktuell;
00046 m_ValueType = FLOAT;
00047 m_maxValue = maxValue;
00048 initChild();
00049 }
00050
00051 void AHUDPoll::init(int maxValue, const int *aktuell)
00052 {
00053 m_iAktuell = aktuell;
00054 m_ValueType = INTEGER;
00055 m_maxValue = maxValue;
00056 initChild();
00057 }
00058
00059
00060
00061 CHUDPollGrafikHorz::CHUDPollGrafikHorz(global_data_pointers data)
00062 {
00063 m_Sprite = new sf::Sprite;
00064 m_Sprite->SetImage(sgl::get_imagemgr().get_img("data/gfx/LifelineHorz.png"));
00065 }
00066
00067 void CHUDPollGrafikHorz::initChild()
00068 {
00069 m_Sprite->SetPosition(m_X, m_Y);
00070 }
00071
00072 void CHUDPollGrafikHorz::draw()
00073 {
00074
00075
00076 float Aktuell = ((m_ValueType == FLOAT) ? *m_fAktuell : (float)*m_iAktuell);
00077 float percentage = Aktuell / m_maxValue;
00078 float scalefactor = percentage * m_Width;
00079 float adapt = (float)m_Height / 50;
00080 m_Sprite->SetScale(scalefactor, adapt);
00081 sgl::get_window().Draw(*m_Sprite);
00082 }
00083
00084
00085 CHUDPollGrafikVert::CHUDPollGrafikVert(global_data_pointers data)
00086 : m_Sprite(new sf::Sprite)
00087 {
00088 m_Sprite->SetImage(sgl::get_imagemgr().get_img("data/gfx/LifelineVert.png"));
00089 }
00090
00091 void CHUDPollGrafikVert::initChild()
00092 {
00093 m_Sprite->SetPosition(m_X, m_Y);
00094 }
00095
00096 void CHUDPollGrafikVert::draw()
00097 {
00098 float Aktuell = ((m_ValueType == FLOAT) ? *m_fAktuell : (float)*m_iAktuell);
00099 float percentage = Aktuell / m_maxValue;
00100 float scalefactor = percentage * m_Height;
00101 float adapt = (float)m_Width / 50;
00102 m_Sprite->SetScale(adapt, scalefactor);
00103 sgl::get_window().Draw(*m_Sprite);
00104 }
00105
00106
00107
00108 void CHUDPollText::init(const std::string *data)
00109 {
00110 m_Data = data;
00111 }
00112
00113 void CHUDPollText::draw()
00114 {
00115 m_bmFont->DrawText(m_X, m_Y, *m_Data, m_fontsize, m_textwidth);
00116 }
00117
00118
00119
00120
00121 void CHUDSetText::draw()
00122 {
00123 m_bmFont->DrawText(m_X, m_Y, m_Data, m_fontsize);
00124 }
00125
00126
00127
00128 void CHUDInfo::init(bool* show, std::list<SInfo*>* Infos)
00129 {
00130 m_timer = 0;
00131 m_backg = new sf::Sprite();
00132 p_show = show;
00133 p_Infos = Infos;
00134
00135 m_backg->SetImage(sgl::get_imagemgr().get_img("data/gfx/Infobgrnd.png"));
00136 m_image = new sf::Sprite();
00137 m_backg->SetPosition(162, 5);
00138 m_backg->SetColor(sf::Color(255, 255, 255, 0));
00139 }
00140
00141 void CHUDInfo::draw()
00142 {
00143 if (!(*p_show) || p_Infos->size() == 0) return;
00144
00145 static unsigned char frame = 0;
00146
00147 int alpha = 255;
00148 if (m_timer == 0)
00149 {
00150 m_image->SetImage(sgl::get_imagemgr().get_img((*(p_Infos->begin()))->image));
00151 m_image->SetSubRect(sf::IntRect(0, 0, 120, 120));
00153 m_image->SetPosition(192, 35);
00154 m_image->SetColor(sf::Color(255, 255, 255, 0));
00155 ++m_timer;
00156 }
00157 if (m_timer < 127)
00158 {
00159 alpha = (m_timer*2);
00160 }
00161 else if (m_timer > 511)
00162 {
00163 if (p_Infos->size() > 1)
00164 {
00165 p_Infos->pop_front();
00166 m_image->SetImage(sgl::get_imagemgr().get_img((*(p_Infos->begin()))->image));
00167 m_image->SetSubRect(sf::IntRect(0, 0, 120, 120));
00169 m_timer = 126;
00170 }
00171 else
00172 {
00173 alpha = 1277 - (m_timer*2);
00174 }
00175 }
00176 if (m_timer > 638)
00177 {
00178 m_timer = 0;
00179 *p_show = false;
00180 if(p_Infos->size() == 1)
00181 {
00182 p_Infos->pop_front();
00183 }
00184 else
00185 {
00186 static log4cxx::LoggerPtr log_ (log4cxx::Logger::getLogger("CHUDInfo.draw"));
00187 LOG4CXX_ERROR(log_, _("Grave error"));
00188 }
00189 }
00190 else
00191 {
00192 m_timer++;
00193
00194 if (alpha > 255) alpha = 255;
00195 if (alpha < 0) alpha = 0;
00196 m_backg->SetColor(sf::Color(255, 255, 255, alpha));
00197 sgl::get_window().Draw(*m_backg);
00198
00199 m_image->SetColor(sf::Color(255, 255, 255, alpha));
00200 sgl::get_window().Draw(*m_image);
00201
00202 if ((frame++)%((*(p_Infos->begin()))->frameofset) == 0)
00203 update_frame(*m_image, (*(p_Infos->begin()))->framecount);
00204
00205 m_bmFont->DrawText(335, 35, (*(p_Infos->begin()))->content, 16, 370, 120, 0, NULL, alpha);
00206 }
00207 }