2010-03-27 19:35:47 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-13 21:08:08 +02:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-27 19:35:47 +01:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code 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
|
|
|
|
|
// ==============================================================
|
|
|
|
|
#include "intro.h"
|
|
|
|
|
|
|
|
|
|
#include "main_menu.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "game_util.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "metrics.h"
|
|
|
|
|
#include "auto_test.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
using namespace Shared::Util;
|
|
|
|
|
using namespace Shared::Graphics;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class Text
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
Text::Text(const string &text, const Vec2i &pos, int time, const Font2D *font){
|
|
|
|
|
this->text= text;
|
|
|
|
|
this->pos= pos;
|
|
|
|
|
this->time= time;
|
|
|
|
|
this->texture= NULL;
|
|
|
|
|
this->font= font;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text::Text(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time){
|
|
|
|
|
this->pos= pos;
|
|
|
|
|
this->size= size;
|
|
|
|
|
this->time= time;
|
|
|
|
|
this->texture= texture;
|
|
|
|
|
this->font= NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class Intro
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
const int Intro::introTime= 24000;
|
|
|
|
|
const int Intro::appearTime= 2500;
|
|
|
|
|
const int Intro::showTime= 2500;
|
|
|
|
|
const int Intro::disapearTime= 2500;
|
|
|
|
|
|
|
|
|
|
Intro::Intro(Program *program):
|
|
|
|
|
ProgramState(program)
|
|
|
|
|
{
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
int w= metrics.getVirtualW();
|
|
|
|
|
int h= metrics.getVirtualH();
|
|
|
|
|
timer=0;
|
2011-01-31 22:59:28 +01:00
|
|
|
|
mouseX = 0;
|
|
|
|
|
mouseY = 0;
|
|
|
|
|
mouse2d = 0;
|
2010-03-27 19:35:47 +01:00
|
|
|
|
|
|
|
|
|
texts.push_back(Text(coreData.getLogoTexture(), Vec2i(w/2-128, h/2-64), Vec2i(256, 128), 4000));
|
2010-04-13 21:08:08 +02:00
|
|
|
|
texts.push_back(Text(glestVersionString, Vec2i(w/2+45, h/2-45), 4000, coreData.getMenuFontNormal()));
|
2011-01-18 22:58:04 +01:00
|
|
|
|
texts.push_back(Text("www.megaglest.org", Vec2i(w/2, h/2), 12000, coreData.getMenuFontVeryBig()));
|
2010-03-27 19:35:47 +01:00
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
soundRenderer.playMusic(CoreData::getInstance().getIntroMusic());
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Intro::update(){
|
|
|
|
|
timer++;
|
|
|
|
|
if(timer>introTime*GameConstants::updateFps/1000){
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
program->setState(new MainMenu(program));
|
2011-02-18 17:15:14 +01:00
|
|
|
|
return;
|
2010-03-27 19:35:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(Config::getInstance().getBool("AutoTest")){
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
AutoTest::getInstance().updateIntro(program);
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
2011-01-31 22:59:28 +01:00
|
|
|
|
|
|
|
|
|
mouse2d= (mouse2d+1) % Renderer::maxMouse2dAnim;
|
2010-03-27 19:35:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Intro::render(){
|
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
int difTime;
|
|
|
|
|
|
|
|
|
|
renderer.reset2d();
|
|
|
|
|
renderer.clearBuffers();
|
|
|
|
|
for(int i=0; i<texts.size(); ++i){
|
|
|
|
|
Text *text= &texts[i];
|
|
|
|
|
|
|
|
|
|
difTime= 1000*timer/GameConstants::updateFps-text->getTime();
|
|
|
|
|
|
|
|
|
|
if(difTime>0 && difTime<appearTime+showTime+disapearTime){
|
|
|
|
|
float alpha= 1.f;
|
|
|
|
|
if(difTime>0 && difTime<appearTime){
|
|
|
|
|
//apearing
|
|
|
|
|
alpha= static_cast<float>(difTime)/appearTime;
|
|
|
|
|
}
|
|
|
|
|
else if(difTime>0 && difTime<appearTime+showTime+disapearTime){
|
|
|
|
|
//disappearing
|
|
|
|
|
alpha= 1.f- static_cast<float>(difTime-appearTime-showTime)/disapearTime;
|
|
|
|
|
}
|
|
|
|
|
if(!text->getText().empty()){
|
|
|
|
|
renderer.renderText(
|
|
|
|
|
text->getText(), text->getFont(), alpha,
|
|
|
|
|
text->getPos().x, text->getPos().y, true);
|
|
|
|
|
}
|
|
|
|
|
if(text->getTexture()!=NULL){
|
|
|
|
|
renderer.renderTextureQuad(
|
|
|
|
|
text->getPos().x, text->getPos().y,
|
|
|
|
|
text->getSize().x, text->getSize().y,
|
|
|
|
|
text->getTexture(), alpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-08 10:29:51 +02:00
|
|
|
|
|
|
|
|
|
if(program != NULL) program->renderProgramMsgBox();
|
|
|
|
|
|
2011-01-31 22:59:28 +01:00
|
|
|
|
if(this->forceMouseRender == true) renderer.renderMouse2d(mouseX, mouseY, mouse2d, 0.f);
|
|
|
|
|
|
2010-03-27 19:35:47 +01:00
|
|
|
|
renderer.swapBuffers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Intro::keyDown(char key){
|
|
|
|
|
mouseUpLeft(0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Intro::mouseUpLeft(int x, int y){
|
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
soundRenderer.stopMusic(CoreData::getInstance().getIntroMusic());
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
soundRenderer.playMusic(CoreData::getInstance().getMenuMusic());
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
|
|
|
|
|
program->setState(new MainMenu(program));
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 22:59:28 +01:00
|
|
|
|
void Intro::mouseMove(int x, int y, const MouseState *ms) {
|
|
|
|
|
mouseX = x;
|
|
|
|
|
mouseY = y;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 19:35:47 +01:00
|
|
|
|
}}//end namespace
|