1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Martio Figueroa
//
// 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 "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 "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
// =====================================================
MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu):
MenuState(program, mainMenu, "root")
{
Lang &lang= Lang::getInstance();
buttonNewGame.init(425, 350, 150);
buttonJoinGame.init(425, 310, 150);
buttonOptions.init(425, 270, 150);
buttonAbout.init(425, 230, 150);
buttonExit.init(425, 190, 150);
labelVersion.init(520, 440);
buttonNewGame.setText(lang.get("NewGame"));
buttonJoinGame.setText(lang.get("JoinGame"));
buttonOptions.setText(lang.get("Options"));
buttonAbout.setText(lang.get("About"));
buttonExit.setText(lang.get("Exit"));
labelVersion.setText(glestVersionString);
}
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));
}
else if(buttonJoinGame.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateJoinGame(program, mainMenu));
}
else if(buttonOptions.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateOptions(program, mainMenu));
}
else if(buttonAbout.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateAbout(program, mainMenu));
}
else if(buttonExit.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundA());
program->exit();
}
}
void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){
buttonNewGame.mouseMove(x, y);
buttonJoinGame.mouseMove(x, y);
buttonOptions.mouseMove(x, y);
buttonAbout.mouseMove(x, y);
buttonExit.mouseMove(x,y);
}
void MenuStateRoot::render(){
Renderer &renderer= Renderer::getInstance();
CoreData &coreData= CoreData::getInstance();
const Metrics &metrics= Metrics::getInstance();
int w= 300;
int h= 150;
renderer.renderTextureQuad(
(metrics.getVirtualW()-w)/2, 475-h/2, w, h,
coreData.getLogoTexture(), GraphicComponent::getFade());
renderer.renderButton(&buttonNewGame);
renderer.renderButton(&buttonJoinGame);
renderer.renderButton(&buttonOptions);
renderer.renderButton(&buttonAbout);
renderer.renderButton(&buttonExit);
renderer.renderLabel(&labelVersion);
}
void MenuStateRoot::update(){
if(Config::getInstance().getBool("AutoTest")){
AutoTest::getInstance().updateRoot(program, mainMenu);
}
}
}}//end namespace
|