[Opentnl-cvs] tnl/zap UICredits.cpp,NONE,1.1 UICredits.h,NONE,1.1 ZAP.vcproj,1.7,1.8
Brought to you by:
mark_frohnmayer,
s_alanet
From: Robert B. Jr. <rbl...@us...> - 2004-04-30 06:56:01
|
Update of /cvsroot/opentnl/tnl/zap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29916/zap Modified Files: ZAP.vcproj Added Files: UICredits.cpp UICredits.h Log Message: Simple exit credits for now. --- NEW FILE: UICredits.cpp --- //----------------------------------------------------------------------------------- // // Torque Network Library - ZAP example multiplayer vector graphics space game // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #include "../tnl/tnlRandom.h" #include "UICredits.h" #include "glutInclude.h" #include <stdio.h> namespace Zap { CreditsUserInterface gCreditsUserInterface; void CreditsUserInterface::onActivate() { // construct the creditsfx objects here, they will // get properly deleted when the CreditsUI // destructor is envoked // add credits scroller first and make it active CreditsScroller *scroller = new CreditsScroller; scroller->setActive(true); // add CreditsFX effects below here, dont activate: // // choose randomly another CreditsFX effect // aside from CreditsScroller to activate if(fxList.size() > 1) { U32 rand = Random::readI(0, fxList.size() - 1); while(fxList[rand]->isActive()) { U32 value = Platform::getRealMilliseconds(); Random::addEntropy((U8 *) &value, sizeof(U32)); rand = Random::readI(0, fxList.size() - 1); } fxList[rand]->setActive(true); } } void CreditsUserInterface::render() { glViewport(0, 0, windowWidth, windowHeight); glClearColor(0, 0, 0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // loop through all the attached effects and // call their render function for(S32 i = 0; i < fxList.size(); i++) if(fxList[i]->isActive()) fxList[i]->render(); } //----------------------------------------------------- // CreditsFX Objects //----------------------------------------------------- CreditsFX::CreditsFX() { activated = false; gCreditsUserInterface.addFX(this); } CreditsScroller::CreditsScroller() { credits.clear(); readCredits("credits.txt"); } void CreditsScroller::updateFX(U32 delta) { // scroll the credits text from bottom to top // based on time for(S32 i = 0; i < credits.size(); i++) { S32 pos = credits[i].currPos.x - (delta / 10); // reached the top, reset if(pos < -CreditSpace) pos = gCreditsUserInterface.canvasHeight + CreditSpace * 3; credits[i].currPos.x = pos; } } void CreditsScroller::render() { // draw the credits text glColor3f(1,1,1); for(S32 i = 0; i < credits.size(); i++) { gCreditsUserInterface.drawCenteredString(credits[i].currPos.x, 25, credits[i].jobBuf); gCreditsUserInterface.drawCenteredString(credits[i].currPos.x + 50, 25, credits[i].nameBuf); } } void CreditsScroller::readCredits(const char *file) { // try and open the file context FILE *f = fopen(file, "r"); if(!f) return; char name[MaxCreditLen]; char job[MaxCreditLen]; S32 pos = gCreditsUserInterface.canvasHeight + CreditSpace; // loop through each line in the credits file, expecting // the credits to be listed in this order: // 1) job // 2) name while(!feof(f)) { CreditsInfo c; // get job fgets(job, MaxCreditLen, f); strcpy(c.jobBuf, job); // get name fgets(name, MaxCreditLen, f); strcpy(c.nameBuf, name); // place credit in cache c.currPos.x = pos; credits.push_back(c); pos += CreditSpace; } // close the file context fclose(f); } }; --- NEW FILE: UICredits.h --- //----------------------------------------------------------------------------------- // // Torque Network Library - ZAP example multiplayer vector graphics space game // Copyright (C) 2004 GarageGames.com, Inc. // For more information see http://www.opentnl.org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // For use in products that are not compatible with the terms of the GNU // General Public License, alternative licensing options are available // from GarageGames.com. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // //------------------------------------------------------------------------------------ #ifndef _UICREDITS_H_ #define _UICREDITS_H_ #include "UI.h" #include "game.h" namespace Zap { class CreditsUserInterface; class CreditsFX { protected: bool activated; public: CreditsFX(); virtual void setActive(bool active) { activated = active; } virtual bool isActive() { return activated; } virtual void updateFX(U32 delta) = 0; virtual void render() = 0; }; class CreditsScroller : public CreditsFX { //typedef CreditsFX Parent; enum Credits { MaxCreditLen = 32, CreditSpace = 200 }; struct CreditsInfo { char nameBuf[MaxCreditLen+1]; char jobBuf[MaxCreditLen+1]; Point currPos; }; Vector<CreditsInfo> credits; void readCredits(const char *file); public: CreditsScroller(); void updateFX(U32 delta); void render(); }; // Credits UI class CreditsUserInterface : public UserInterface { Vector<CreditsFX *> fxList; public: ~CreditsUserInterface() { for(S32 i = 0; i < fxList.size(); i++) { delete fxList[i]; fxList[i] = NULL; fxList.erase(i); } fxList.clear(); } void onActivate(); void addFX(CreditsFX *fx) { fxList.push_back(fx); } void idle(U32 t) { for(S32 i = 0; i < fxList.size(); i++) if(fxList[i]->isActive()) fxList[i]->updateFX(t); } void render(); void onKeyDown(U32 key) { exit(0); } // exit for now }; extern CreditsUserInterface gCreditsUserInterface; } #endif Index: ZAP.vcproj =================================================================== RCS file: /cvsroot/opentnl/tnl/zap/ZAP.vcproj,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ZAP.vcproj 27 Apr 2004 22:36:47 -0000 1.7 --- ZAP.vcproj 30 Apr 2004 06:55:52 -0000 1.8 *************** *** 259,262 **** --- 259,268 ---- </File> <File + RelativePath=".\UICredits.cpp"> + </File> + <File + RelativePath=".\UICredits.h"> + </File> + <File RelativePath=".\UIGame.cpp"> </File> *************** *** 265,268 **** --- 271,280 ---- </File> <File + RelativePath=".\UILevelEditor.cpp"> + </File> + <File + RelativePath=".\UILevelEditor.h"> + </File> + <File RelativePath=".\UIMenus.cpp"> </File> |