2010-04-04 06:14:27 +02:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
|
|
|
//
|
2010-12-09 21:41:11 +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
|
2010-04-04 06:14:27 +02:00
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
2010-12-09 21:41:11 +01:00
|
|
|
#include "main_menu.h"
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
#include "renderer.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "program.h"
|
2010-12-09 21:41:11 +01:00
|
|
|
#include "game_util.h"
|
2010-04-04 06:14:27 +02:00
|
|
|
#include "game.h"
|
|
|
|
#include "platform_util.h"
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
#include "core_data.h"
|
|
|
|
#include "faction.h"
|
|
|
|
#include "metrics.h"
|
|
|
|
#include "network_manager.h"
|
|
|
|
#include "network_message.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "menu_state_root.h"
|
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using namespace Shared::Sound;
|
|
|
|
using namespace Shared::Platform;
|
|
|
|
using namespace Shared::Util;
|
|
|
|
using namespace Shared::Graphics;
|
|
|
|
using namespace Shared::Xml;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class MainMenu
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
// ===================== PUBLIC ========================
|
2010-04-23 01:18:04 +02:00
|
|
|
MenuState * MainMenu::oldstate=NULL;
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
MainMenu::MainMenu(Program *program):
|
|
|
|
ProgramState(program)
|
|
|
|
{
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2010-12-09 21:41:11 +01:00
|
|
|
mouseX=100;
|
2010-04-04 06:14:27 +02:00
|
|
|
mouseY=100;
|
|
|
|
|
|
|
|
state= NULL;
|
|
|
|
this->program= program;
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
setState(new MenuStateRoot(program, this));
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainMenu::~MainMenu() {
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
delete state;
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
Renderer::getInstance().endMenu();
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2011-01-18 02:24:45 +01:00
|
|
|
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
//soundRenderer.stopAllSounds();
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 09:18:06 +02:00
|
|
|
void MainMenu::init() {
|
2010-04-04 06:14:27 +02:00
|
|
|
Renderer::getInstance().initMenu(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//asynchronus render update
|
2011-06-08 09:18:06 +02:00
|
|
|
void MainMenu::render() {
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
Config &config= Config::getInstance();
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
2011-07-01 04:50:20 +02:00
|
|
|
//fps++;
|
|
|
|
canRender();
|
|
|
|
incrementFps();
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2010-09-12 07:05:08 +02:00
|
|
|
renderer.clearBuffers();
|
2010-12-09 21:41:11 +01:00
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
//3d
|
|
|
|
renderer.reset3dMenu();
|
2010-09-12 07:05:08 +02:00
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
renderer.clearZBuffer();
|
|
|
|
renderer.loadCameraMatrix(menuBackground.getCamera());
|
|
|
|
renderer.renderMenuBackground(&menuBackground);
|
|
|
|
renderer.renderParticleManager(rsMenu);
|
|
|
|
|
|
|
|
//2d
|
|
|
|
renderer.reset2d();
|
|
|
|
state->render();
|
|
|
|
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
|
|
|
|
|
2011-07-01 04:50:20 +02:00
|
|
|
renderer.renderFPSWhenEnabled(lastFps);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
renderer.swapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
//syncronus update
|
|
|
|
void MainMenu::update(){
|
|
|
|
Renderer::getInstance().updateParticleManager(rsMenu);
|
|
|
|
mouse2dAnim= (mouse2dAnim +1) % Renderer::maxMouse2dAnim;
|
|
|
|
menuBackground.update();
|
|
|
|
state->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//event magangement: mouse click
|
|
|
|
void MainMenu::mouseMove(int x, int y, const MouseState *ms){
|
|
|
|
mouseX= x; mouseY= y;
|
|
|
|
state->mouseMove(x, y, ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
//returns if exiting
|
|
|
|
void MainMenu::mouseDownLeft(int x, int y){
|
2010-12-09 21:41:11 +01:00
|
|
|
state->mouseClick(x, y, mbLeft);
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::mouseDownRight(int x, int y){
|
2010-12-09 21:41:11 +01:00
|
|
|
state->mouseClick(x, y, mbRight);
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
2011-06-26 03:55:08 +02:00
|
|
|
void MainMenu::keyDown(SDL_KeyboardEvent key) {
|
2010-04-04 06:14:27 +02:00
|
|
|
state->keyDown(key);
|
|
|
|
}
|
|
|
|
|
2011-06-26 03:55:08 +02:00
|
|
|
void MainMenu::keyUp(SDL_KeyboardEvent key) {
|
2010-06-08 02:00:28 +02:00
|
|
|
state->keyUp(key);
|
|
|
|
}
|
|
|
|
|
2011-06-26 03:55:08 +02:00
|
|
|
void MainMenu::keyPress(SDL_KeyboardEvent c) {
|
2010-04-04 06:14:27 +02:00
|
|
|
state->keyPress(c);
|
|
|
|
}
|
|
|
|
|
2011-01-02 10:33:37 +01:00
|
|
|
void MainMenu::setState(MenuState *newstate) {
|
2011-01-02 10:34:14 +01:00
|
|
|
//printf("In [%s::%s Line: %d] oldstate [%p] newstate [%p] this->state [%p]\n",__FILE__,__FUNCTION__,__LINE__,oldstate,newstate,this->state);
|
2011-01-02 10:33:37 +01:00
|
|
|
|
|
|
|
//delete this->state;
|
|
|
|
//this->state = newstate;
|
|
|
|
|
|
|
|
if(oldstate != NULL && oldstate != newstate) {
|
2010-05-01 22:14:25 +02:00
|
|
|
delete oldstate;
|
|
|
|
|
2010-12-23 01:00:30 +01:00
|
|
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-01 22:14:25 +02:00
|
|
|
if(oldstate != this->state) {
|
|
|
|
oldstate=this->state;
|
2010-12-23 01:00:30 +01:00
|
|
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-01 22:14:25 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
oldstate = NULL;
|
2010-12-23 01:00:30 +01:00
|
|
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-01 22:14:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
oldstate=this->state;
|
2010-12-23 01:00:30 +01:00
|
|
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-05-01 22:14:25 +02:00
|
|
|
}
|
2010-12-23 01:00:30 +01:00
|
|
|
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2011-01-02 10:33:37 +01:00
|
|
|
this->state= newstate;
|
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
GraphicComponent::resetFade();
|
2011-01-02 10:33:37 +01:00
|
|
|
menuBackground.setTargetCamera(newstate->getCamera());
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
2010-07-29 17:49:06 +02:00
|
|
|
bool MainMenu::isInSpecialKeyCaptureEvent() {
|
|
|
|
return state->isInSpecialKeyCaptureEvent();
|
|
|
|
}
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2011-04-15 03:05:36 +02:00
|
|
|
void MainMenu::consoleAddLine(string line) {
|
|
|
|
if(state != NULL) {
|
|
|
|
state->consoleAddLine(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
// =====================================================
|
|
|
|
// class MenuState
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
MenuState::MenuState(Program *program, MainMenu *mainMenu, const string &stateName){
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
this->containerName="";
|
2010-04-04 06:14:27 +02:00
|
|
|
this->program= program;
|
|
|
|
this->mainMenu= mainMenu;
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-04 01:15:42 +02:00
|
|
|
//switch on menu music again, it might be muted
|
|
|
|
Config &config = Config::getInstance();
|
|
|
|
float configVolume = (config.getInt("SoundVolumeMusic") / 100.f);
|
|
|
|
CoreData::getInstance().getMenuMusic()->setVolume(configVolume);
|
2010-12-09 21:41:11 +01:00
|
|
|
|
|
|
|
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
//camera
|
|
|
|
XmlTree xmlTree;
|
2011-05-07 00:12:16 +02:00
|
|
|
xmlTree.load(data_path + "data/core/menu/menu.xml",Properties::getTagReplacementValues());
|
2010-04-04 06:14:27 +02:00
|
|
|
const XmlNode *menuNode= xmlTree.getRootNode();
|
|
|
|
const XmlNode *cameraNode= menuNode->getChild("camera");
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
//position
|
|
|
|
const XmlNode *positionNode= cameraNode->getChild(stateName + "-position");
|
|
|
|
Vec3f startPosition;
|
|
|
|
startPosition.x= positionNode->getAttribute("x")->getFloatValue();
|
|
|
|
startPosition.y= positionNode->getAttribute("y")->getFloatValue();
|
|
|
|
startPosition.z= positionNode->getAttribute("z")->getFloatValue();
|
|
|
|
camera.setPosition(startPosition);
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
|
|
|
|
//rotation
|
|
|
|
const XmlNode *rotationNode= cameraNode->getChild(stateName + "-rotation");
|
|
|
|
Vec3f startRotation;
|
|
|
|
startRotation.x= rotationNode->getAttribute("x")->getFloatValue();
|
|
|
|
startRotation.y= rotationNode->getAttribute("y")->getFloatValue();
|
|
|
|
startRotation.z= rotationNode->getAttribute("z")->getFloatValue();
|
|
|
|
camera.setOrientation(Quaternion(EulerAngles(
|
2010-12-09 21:41:11 +01:00
|
|
|
degToRad(startRotation.x),
|
|
|
|
degToRad(startRotation.y),
|
2010-04-04 06:14:27 +02:00
|
|
|
degToRad(startRotation.z))));
|
|
|
|
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-04-04 06:14:27 +02:00
|
|
|
}
|
|
|
|
|
2010-09-09 08:42:39 +02:00
|
|
|
MenuState::~MenuState() {
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 23:07:39 +02:00
|
|
|
GraphicComponent::clearRegisteredComponents(this->containerName);
|
2011-03-29 11:45:15 +02:00
|
|
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 08:42:39 +02:00
|
|
|
}
|
|
|
|
|
2011-04-15 03:05:36 +02:00
|
|
|
void MenuState::consoleAddLine(string line) {
|
|
|
|
console.addLine(line);
|
|
|
|
}
|
2010-09-09 08:42:39 +02:00
|
|
|
|
2010-04-04 06:14:27 +02:00
|
|
|
}}//end namespace
|