00001 #include <game.h>
00002
00003 credit::credit() : base("credit"), activate(false), newY(0),y(0)
00004 {
00005 logos = new std::vector<IGUIImage*>;
00006 texts = new std::vector<IGUIStaticText*>;
00007 }
00008
00009 credit::~credit()
00010 {
00011 delete texts;
00012 delete logos;
00013 }
00014
00015 int credit::init(coeur *c,IGUIEnvironment *e,IXMLReader* xmlCredit)
00016 {
00017 base::init(0,c);
00018 env = e;
00019
00020 log(stringc("Credit xml loading ..."));
00021
00022 activate=false;
00023 newY=c->getDim().Height + 40;
00024 y=0;
00025 while(xmlCredit && xmlCredit->read())
00026 {
00027 if (xmlCredit->getNodeType()==EXN_ELEMENT)
00028 {
00029 if (core::stringw("credit") == xmlCredit->getNodeName())
00030 {
00031 logos->reserve(xmlCredit->getAttributeValueAsInt(L"nbrlogo"));
00032 texts->reserve(xmlCredit->getAttributeValueAsInt(L"nbrtext"));
00033 }
00034 else if (core::stringw("logo") == xmlCredit->getNodeName())
00035 {
00036 addLogo(xmlCredit->getAttributeValue(L"path"));
00037 log( stringc("Add logo : \"") + xmlCredit->getAttributeValue(L"path") + "\"");
00038 }
00039 else if (core::stringw("text") == xmlCredit->getNodeName())
00040 {
00041 addText(xmlCredit->getAttributeValue(L"text"));
00042 log( stringc("Add text : \"") + xmlCredit->getAttributeValue(L"text") + "\"");
00043 }
00044 else if (core::stringw("sound") == xmlCredit->getNodeName())
00045 {
00046 sound = xmlCredit->getAttributeValue(L"path");
00047 log( stringc("Sound : \"") + xmlCredit->getAttributeValue(L"path") + "\"");
00048 }
00049 }
00050 }
00051
00052 return 1;
00053 }
00054
00055 int credit::update()
00056 {
00057
00058
00059 if (activate)
00060 {
00061 if (y++ >= newY)
00062 stop();
00063 if (y%1!=0)
00064 return 1;
00065 for (int i=logos->size()-1;i>-1;i--)
00066 {
00067 (*logos)[i]->setRelativePosition( logos->at(i)->getRelativePosition() - position2d<s32>(0,1) );
00068 }
00069
00070 for (int i=texts->size()-1;i>-1;i--)
00071 {
00072 (*texts)[i]->setRelativePosition( texts->at(i)->getRelativePosition() - position2d<s32>(0,1) );
00073 }
00074 }
00075 return 1;
00076 }
00077
00078 int credit::close()
00079 {
00080 stop();
00081
00082 log("Deleting logos");
00083 while (!logos->empty())
00084 {
00085 log("Deleting last logo");
00086 logos->pop_back();
00087 }
00088
00089 log("Deleting texts");
00090 while (!texts->empty())
00091 {
00092 log("Deleting last text");
00093 texts->pop_back();
00094 }
00095
00096 base::close();
00097 return 1;
00098 }
00099
00100 int credit::start()
00101 {
00102 activate = true;
00103 y=0;
00104 mycore->play(sound);
00105 log("Credit start");
00106 return 1;
00107 }
00108
00109 int credit::stop()
00110 {
00111 if (!activate)
00112 return 0;
00113 for (unsigned int i=0;i<logos->size();i++)
00114 {
00115 (*logos)[i]->setRelativePosition( logos->at(i)->getRelativePosition() + position2d<s32>(0,y) );
00116 }
00117
00118 for (unsigned int i=0;i<texts->size();i++)
00119 {
00120 (*texts)[i]->setRelativePosition( texts->at(i)->getRelativePosition() + position2d<s32>(0,y) );
00121 }
00122 activate = false;
00123 log("Credit stop");
00124 return 1;
00125 }
00126
00127 int credit::addLogo(stringc path)
00128 {
00129 if (activate)
00130 return 0;
00131 IGUIImage* img = env->addImage( mycore->getTexture( path.c_str() ), position2d<s32>(0,newY) );
00132 rect<s32> dim = img->getRelativePosition();
00133 int w = dim.getWidth();
00134 dim.UpperLeftCorner = position2d<s32>( (mycore->getDim().Width - w)/2 , newY);
00135 dim.LowerRightCorner = position2d<s32>( (mycore->getDim().Width + w)/2 , dim.LowerRightCorner.Y);
00136 img->setRelativePosition(dim);
00137 logos->push_back(img);
00138 newY += 50;
00139 log("Image added");
00140 return 1;
00141 }
00142
00143 int credit::addText(stringw text)
00144 {
00145 if (activate)
00146 return 0;
00147 IGUIStaticText* txt = env->addStaticText( text.c_str(), rect<s32>(200,newY,mycore->getDim().Width-200,newY+20) );
00148 txt->setTextAlignment(EGUIA_CENTER,EGUIA_CENTER);
00149 texts->push_back(txt);
00150 newY += 20;
00151 log("Text added");
00152 return 1;
00153 }
00154
00155
00156 bool credit::OnEvent(const SEvent& event)
00157 {
00158 return false;
00159 }
00160