2010-05-09 23:23:13 +02:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
|
|
|
|
//
|
2010-12-10 02:53:51 +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-05-09 23:23:13 +02:00
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "menu_state_root.h"
|
|
|
|
|
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "sound_renderer.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "menu_state_new_game.h"
|
|
|
|
|
#include "menu_state_join_game.h"
|
|
|
|
|
#include "menu_state_options.h"
|
|
|
|
|
#include "menu_state_about.h"
|
|
|
|
|
#include "menu_state_masterserver.h"
|
|
|
|
|
#include "metrics.h"
|
|
|
|
|
#include "network_manager.h"
|
|
|
|
|
#include "network_message.h"
|
|
|
|
|
#include "socket.h"
|
|
|
|
|
#include "auto_test.h"
|
|
|
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class MenuStateRoot
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-12-10 02:53:51 +01:00
|
|
|
|
MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu):
|
2010-05-09 23:23:13 +02:00
|
|
|
|
MenuState(program, mainMenu, "root")
|
|
|
|
|
{
|
2010-09-09 23:07:39 +02:00
|
|
|
|
containerName = "MainMenu";
|
2010-05-09 23:23:13 +02:00
|
|
|
|
Lang &lang= Lang::getInstance();
|
2011-01-12 20:42:25 +01:00
|
|
|
|
int yPos=440;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
|
2011-01-12 20:42:25 +01:00
|
|
|
|
|
|
|
|
|
labelVersion.registerGraphicComponent(containerName,"labelVersion");
|
|
|
|
|
if(EndsWith(glestVersionString, "-dev") == false){
|
|
|
|
|
labelVersion.init(525, yPos);
|
|
|
|
|
labelVersion.setText(glestVersionString);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
labelVersion.init(405, yPos);
|
|
|
|
|
labelVersion.setText(glestVersionString + " [" + getCompileDateTime() + ", " + getSVNRevisionString() + "]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yPos-=55;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonNewGame.registerGraphicComponent(containerName,"buttonNewGame");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonNewGame.init(425, yPos, 150);
|
|
|
|
|
yPos-=40;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonJoinGame.registerGraphicComponent(containerName,"buttonJoinGame");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonJoinGame.init(425, yPos, 150);
|
|
|
|
|
yPos-=40;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonMasterserverGame.registerGraphicComponent(containerName,"buttonMasterserverGame");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonMasterserverGame.init(425, yPos, 150);
|
|
|
|
|
yPos-=40;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonOptions.registerGraphicComponent(containerName,"buttonOptions");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonOptions.init(425, yPos, 150);
|
|
|
|
|
yPos-=40;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonAbout.registerGraphicComponent(containerName,"buttonAbout");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonAbout.init(425, yPos , 150);
|
|
|
|
|
yPos-=40;
|
2010-09-09 08:42:39 +02:00
|
|
|
|
buttonExit.registerGraphicComponent(containerName,"buttonExit");
|
2011-01-12 20:42:25 +01:00
|
|
|
|
buttonExit.init(425, yPos, 150);
|
2010-05-09 23:23:13 +02:00
|
|
|
|
|
|
|
|
|
buttonNewGame.setText(lang.get("NewGame"));
|
|
|
|
|
buttonJoinGame.setText(lang.get("JoinGame"));
|
2010-05-13 09:22:33 +02:00
|
|
|
|
buttonMasterserverGame.setText(lang.get("JoinInternetGame"));
|
2010-05-09 23:23:13 +02:00
|
|
|
|
buttonOptions.setText(lang.get("Options"));
|
2010-12-10 02:53:51 +01:00
|
|
|
|
buttonAbout.setText(lang.get("About"));
|
2010-05-09 23:23:13 +02:00
|
|
|
|
buttonExit.setText(lang.get("Exit"));
|
2010-12-11 01:20:31 +01:00
|
|
|
|
|
2010-06-12 21:27:11 +02:00
|
|
|
|
//mesage box
|
2010-09-09 08:42:39 +02:00
|
|
|
|
mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
|
2010-06-12 21:27:11 +02:00
|
|
|
|
mainMessageBox.init(lang.get("Yes"), lang.get("No"));
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
|
2010-09-09 08:42:39 +02:00
|
|
|
|
GraphicComponent::applyAllCustomProperties(containerName);
|
2010-05-09 23:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){
|
|
|
|
|
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
|
|
|
|
|
|
|
|
|
if(buttonNewGame.mouseClick(x, y)){
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundB());
|
|
|
|
|
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
|
2010-12-10 02:53:51 +01:00
|
|
|
|
}
|
2010-05-09 23:23:13 +02:00
|
|
|
|
else if(buttonJoinGame.mouseClick(x, y)){
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundB());
|
|
|
|
|
mainMenu->setState(new MenuStateJoinGame(program, mainMenu));
|
|
|
|
|
}
|
|
|
|
|
else if(buttonMasterserverGame.mouseClick(x, y)){
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundB());
|
|
|
|
|
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
|
|
|
|
|
}
|
2010-12-10 02:53:51 +01:00
|
|
|
|
else if(buttonOptions.mouseClick(x, y)){
|
2010-05-09 23:23:13 +02:00
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundB());
|
|
|
|
|
mainMenu->setState(new MenuStateOptions(program, mainMenu));
|
|
|
|
|
}
|
2010-12-10 02:53:51 +01:00
|
|
|
|
else if(buttonAbout.mouseClick(x, y)){
|
2010-05-09 23:23:13 +02:00
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundB());
|
|
|
|
|
mainMenu->setState(new MenuStateAbout(program, mainMenu));
|
|
|
|
|
}
|
|
|
|
|
else if(buttonExit.mouseClick(x, y)){
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
|
program->exit();
|
|
|
|
|
}
|
2010-06-12 21:27:11 +02:00
|
|
|
|
//exit message box, has to be the last thing to do in this function
|
|
|
|
|
else if(mainMessageBox.getEnabled()){
|
|
|
|
|
int button= 1;
|
|
|
|
|
if(mainMessageBox.mouseClick(x, y, button)) {
|
|
|
|
|
if(button==1) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
soundRenderer.playFx(coreData.getClickSoundA());
|
|
|
|
|
program->exit();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
//close message box
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-09 23:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){
|
|
|
|
|
buttonNewGame.mouseMove(x, y);
|
|
|
|
|
buttonJoinGame.mouseMove(x, y);
|
|
|
|
|
buttonMasterserverGame.mouseMove(x, y);
|
|
|
|
|
buttonOptions.mouseMove(x, y);
|
2010-12-10 02:53:51 +01:00
|
|
|
|
buttonAbout.mouseMove(x, y);
|
2010-05-09 23:23:13 +02:00
|
|
|
|
buttonExit.mouseMove(x,y);
|
2010-06-12 21:27:11 +02:00
|
|
|
|
if (mainMessageBox.getEnabled()) {
|
|
|
|
|
mainMessageBox.mouseMove(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 23:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 08:42:39 +02:00
|
|
|
|
void MenuStateRoot::render() {
|
2010-05-09 23:23:13 +02:00
|
|
|
|
Renderer &renderer= Renderer::getInstance();
|
|
|
|
|
CoreData &coreData= CoreData::getInstance();
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
2010-12-10 02:53:51 +01:00
|
|
|
|
|
2010-05-09 23:23:13 +02:00
|
|
|
|
int w= 300;
|
|
|
|
|
int h= 150;
|
2011-01-12 20:42:25 +01:00
|
|
|
|
int yPos=495;
|
2010-05-09 23:23:13 +02:00
|
|
|
|
|
|
|
|
|
renderer.renderTextureQuad(
|
2011-01-12 20:42:25 +01:00
|
|
|
|
(metrics.getVirtualW()-w)/2, yPos-h/2, w, h,
|
2010-05-09 23:23:13 +02:00
|
|
|
|
coreData.getLogoTexture(), GraphicComponent::getFade());
|
2010-08-06 00:27:26 +02:00
|
|
|
|
|
|
|
|
|
int maxLogoWidth=0;
|
|
|
|
|
for(int idx = 0; idx < coreData.getLogoTextureExtraCount(); ++idx) {
|
|
|
|
|
Texture2D *extraLogo = coreData.getLogoTextureExtra(idx);
|
|
|
|
|
maxLogoWidth += extraLogo->getPixmap()->getW();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int currentX = (metrics.getVirtualW()-maxLogoWidth)/2;
|
|
|
|
|
int currentY = 50;
|
|
|
|
|
for(int idx = 0; idx < coreData.getLogoTextureExtraCount(); ++idx) {
|
|
|
|
|
Texture2D *extraLogo = coreData.getLogoTextureExtra(idx);
|
|
|
|
|
|
|
|
|
|
renderer.renderTextureQuad(
|
|
|
|
|
currentX, currentY,
|
|
|
|
|
extraLogo->getPixmap()->getW(), extraLogo->getPixmap()->getH(),
|
|
|
|
|
extraLogo, GraphicComponent::getFade());
|
|
|
|
|
|
|
|
|
|
currentX += extraLogo->getPixmap()->getW();
|
|
|
|
|
}
|
2010-05-09 23:23:13 +02:00
|
|
|
|
renderer.renderButton(&buttonNewGame);
|
|
|
|
|
renderer.renderButton(&buttonJoinGame);
|
|
|
|
|
renderer.renderButton(&buttonMasterserverGame);
|
|
|
|
|
renderer.renderButton(&buttonOptions);
|
|
|
|
|
renderer.renderButton(&buttonAbout);
|
|
|
|
|
renderer.renderButton(&buttonExit);
|
|
|
|
|
renderer.renderLabel(&labelVersion);
|
2010-06-12 21:27:11 +02:00
|
|
|
|
|
|
|
|
|
//exit message box
|
|
|
|
|
if(mainMessageBox.getEnabled()){
|
|
|
|
|
renderer.renderMessageBox(&mainMessageBox);
|
|
|
|
|
}
|
2010-07-08 10:29:51 +02:00
|
|
|
|
if(program != NULL) program->renderProgramMsgBox();
|
2010-05-09 23:23:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateRoot::update(){
|
|
|
|
|
if(Config::getInstance().getBool("AutoTest")){
|
|
|
|
|
AutoTest::getInstance().updateRoot(program, mainMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-12 21:27:11 +02:00
|
|
|
|
void MenuStateRoot::keyDown(char key) {
|
|
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key);
|
|
|
|
|
|
|
|
|
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
|
|
|
|
//exit
|
|
|
|
|
if(key == configKeys.getCharKey("ExitKey")) {
|
|
|
|
|
Lang &lang= Lang::getInstance();
|
|
|
|
|
showMessageBox(lang.get("ExitGame?"), "", true);
|
|
|
|
|
}
|
|
|
|
|
else if(mainMessageBox.getEnabled() == true && key == vkReturn) {
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
|
|
|
|
program->exit();
|
|
|
|
|
}
|
2010-09-09 23:07:39 +02:00
|
|
|
|
else if(key == configKeys.getCharKey("SaveGUILayout")) {
|
|
|
|
|
bool saved = GraphicComponent::saveAllCustomProperties(containerName);
|
|
|
|
|
//Lang &lang= Lang::getInstance();
|
|
|
|
|
//console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]");
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-12 21:27:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuStateRoot::showMessageBox(const string &text, const string &header, bool toggle){
|
|
|
|
|
if(!toggle){
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!mainMessageBox.getEnabled()){
|
|
|
|
|
mainMessageBox.setText(text);
|
|
|
|
|
mainMessageBox.setHeader(header);
|
|
|
|
|
mainMessageBox.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
mainMessageBox.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-09 23:23:13 +02:00
|
|
|
|
}}//end namespace
|