first steps for masterserver join menu

This commit is contained in:
Titus Tscharntke
2010-05-09 21:23:13 +00:00
parent 247cf32531
commit 13a1630e69
7 changed files with 691 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
#include "menu_state_connected_game.h"
#include "menu_state_join_game.h"
#include "menu_state_masterserver.h"
#include "renderer.h"
#include "sound_renderer.h"
#include "core_data.h"
@@ -44,9 +45,10 @@ struct FormatString {
// class MenuStateConnectedGame
// =====================================================
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots):
MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots):
MenuState(program, mainMenu, "join-game")
{
returnMenuInfo=joinMenuInfo;
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
Config &config = Config::getInstance();
@@ -193,7 +195,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
networkManager.end();
currentFactionName="";
currentMap="";
mainMenu->setState(new MenuStateJoinGame(program, mainMenu));
returnToJoinMenu();
}
else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -304,6 +306,18 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateConnectedGame::returnToJoinMenu(){
if(returnMenuInfo==jmSimple)
{
mainMenu->setState(new MenuStateJoinGame(program, mainMenu));
}
else
{
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
}
}
void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms){
buttonDisconnect.mouseMove(x, y);
@@ -466,7 +480,7 @@ void MenuStateConnectedGame::update()
{
clientInterface->close();
}
mainMenu->setState(new MenuStateJoinGame(program, mainMenu));
returnToJoinMenu();
return;
}

View File

@@ -17,6 +17,14 @@
namespace Glest{ namespace Game{
enum JoinMenu{
jmSimple,
jmMasterserver,
jmCount
};
// ===============================
// class MenuStateConnectedGame
// ===============================
@@ -60,11 +68,12 @@ private:
string currentFactionName;
string currentMap;
JoinMenu returnMenuInfo;
bool settingsReceivedFromServer;
public:
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots= false);
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false);
void mouseClick(int x, int y, MouseButton mouseButton);
void mouseMove(int x, int y, const MouseState *mouseState);
@@ -79,6 +88,7 @@ private:
bool hasNetworkGameSettings();
void reloadFactions();
bool loadFactions(const GameSettings *gameSettings);
void returnToJoinMenu();
};
}}//end namespace

View File

@@ -0,0 +1,308 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2010- by Titus Tscharntke
//
// 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_masterserver.h"
#include "renderer.h"
#include "sound_renderer.h"
#include "core_data.h"
#include "config.h"
#include "menu_state_connected_game.h"
#include "menu_state_root.h"
#include "metrics.h"
#include "network_manager.h"
#include "network_message.h"
#include "auto_test.h"
#include "socket.h"
#include "masterserver_info.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
// =====================================================
// class ServerLine
// =====================================================
ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex)
{
Lang &lang= Lang::getInstance();
index=lineIndex;
int lineOffset=25*lineIndex;
masterServerInfo=mServerInfo;
int i=50;
int startOffset=650;
//general info:
i+=10;
glestVersionLabel.init(i,startOffset-lineOffset);
glestVersionLabel.setText(masterServerInfo->getGlestVersion());
i+=80;
platformLabel.init(i,startOffset-lineOffset);
platformLabel.setText(masterServerInfo->getPlatform());
i+=50;
binaryCompileDateLabel.init(i,startOffset-lineOffset);
binaryCompileDateLabel.setText(masterServerInfo->getBinaryCompileDate());
//game info:
i+=70;
serverTitleLabel.init(i,startOffset-lineOffset);
serverTitleLabel.setText(masterServerInfo->getServerTitle());
i+=150;
ipAddressLabel.init(i,startOffset-lineOffset);
ipAddressLabel.setText(masterServerInfo->getIpAddress());
//game setup info:
i+=100;
techLabel.init(i,startOffset-lineOffset);
techLabel.setText(masterServerInfo->getTech());
i+=100;
mapLabel.init(i,startOffset-lineOffset);
mapLabel.setText(masterServerInfo->getMap());
i+=100;
tilesetLabel.init(i,startOffset-lineOffset);
tilesetLabel.setText(masterServerInfo->getTileset());
i+=100;
activeSlotsLabel.init(i,startOffset-lineOffset);
activeSlotsLabel.setText(intToStr(masterServerInfo->getActiveSlots())+"/"+intToStr(masterServerInfo->getNetworkSlots())+"/"+intToStr(masterServerInfo->getConnectedClients()));
i+=50;
selectButton.init(i, startOffset-lineOffset, 30);
selectButton.setText(">");
}
ServerLine::~ServerLine(){
delete masterServerInfo;
}
bool ServerLine::buttonMouseClick(int x, int y){
return selectButton.mouseClick(x,y);
}
bool ServerLine::buttonMouseMove(int x, int y){
return selectButton.mouseMove(x,y);
}
void ServerLine::render(){
Renderer &renderer= Renderer::getInstance();
renderer.renderButton(&selectButton);
//general info:
renderer.renderLabel(&glestVersionLabel);
renderer.renderLabel(&platformLabel);
renderer.renderLabel(&binaryCompileDateLabel);
//game info:
renderer.renderLabel(&serverTitleLabel);
renderer.renderLabel(&ipAddressLabel);
//game setup info:
renderer.renderLabel(&techLabel);
renderer.renderLabel(&mapLabel);
renderer.renderLabel(&tilesetLabel);
renderer.renderLabel(&activeSlotsLabel);
}
// =====================================================
// class MenuStateMasterserver
// =====================================================
MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMenu):
MenuState(program, mainMenu, "root")
{
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"));
mainMessageBox.setEnabled(false);
mainMessageBoxState=0;
// header
labelTitle.init(330, 700);
labelTitle.setText(lang.get("Available Servers"));
buttonRefresh.init(450, 70, 150);
buttonReturn.init(150, 70, 150);
buttonRefresh.setText(lang.get("Refresh List"));
buttonReturn.setText(lang.get("Return"));
NetworkManager::getInstance().end();
NetworkManager::getInstance().init(nrClient);
updateServerInfo();
}
MenuStateMasterserver::~MenuStateMasterserver() {
clearServerLines();
}
void MenuStateMasterserver::clearServerLines(){
while(!serverLines.empty()){
delete serverLines.back();
serverLines.pop_back();
}
}
void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
if(mainMessageBox.getEnabled()){
int button= 1;
if(mainMessageBox.mouseClick(x, y, button))
{
soundRenderer.playFx(coreData.getClickSoundA());
if(button==1)
{
mainMessageBox.setEnabled(false);
}
}
}
else if(buttonRefresh.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
updateServerInfo();
}
else if(buttonReturn.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateRoot(program, mainMenu));
}
else{
for(int i=0; i<serverLines.size(); ++i){
if(serverLines[i]->buttonMouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
connectToServer(serverLines[i]->getMasterServerInfo()->getIpAddress());
break;
}
}
}
}
void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
if (mainMessageBox.getEnabled()) {
mainMessageBox.mouseMove(x, y);
}
buttonRefresh.mouseMove(x, y);
buttonReturn.mouseMove(x, y);
for(int i=0; i<serverLines.size(); ++i){
serverLines[i]->buttonMouseMove(x, y);
}
}
void MenuStateMasterserver::render(){
Renderer &renderer= Renderer::getInstance();
if(mainMessageBox.getEnabled()){
renderer.renderMessageBox(&mainMessageBox);
}
else
{
renderer.renderButton(&buttonRefresh);
renderer.renderButton(&buttonReturn);
renderer.renderLabel(&labelTitle);
for(int i=0; i<serverLines.size(); ++i){
serverLines[i]->render();
}
}
}
void MenuStateMasterserver::update(){
}
void MenuStateMasterserver::updateServerInfo(){
//MasterServerInfos masterServerInfos;
clearServerLines();
for(int i=0; i<10;i++){
MasterServerInfo *masterServerInfo=new MasterServerInfo();
//general info:
masterServerInfo->setGlestVersion("3.3.5-dev");
masterServerInfo->setPlatform("Linux");
masterServerInfo->setBinaryCompileDate("11.05.69");
//game info:
masterServerInfo->setServerTitle("Titis Server");
masterServerInfo->setIpAddress("172.20.100.101");
//game setup info:
masterServerInfo->setTech("Indian");
masterServerInfo->setMap("Conflict");
masterServerInfo->setTileset("Autumn");
masterServerInfo->setActiveSlots(8);
masterServerInfo->setNetworkSlots(4);
masterServerInfo->setConnectedClients(0);
serverLines.push_back(new ServerLine( masterServerInfo, i));
}
//masterServerInfos.push_back(masterServerInfo);
}
void MenuStateMasterserver::connectToServer(string ipString)
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START ipString='%s'\n",__FILE__,__FUNCTION__,ipString.c_str());
ClientInterface* clientInterface= NetworkManager::getInstance().getClientInterface();
Config& config= Config::getInstance();
Ip serverIp(ipString);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] try to connect to [%s]\n",__FILE__,__FUNCTION__,serverIp.getString().c_str());
clientInterface->connect(serverIp, GameConstants::serverPort);
if(!clientInterface->isConnected())
{
NetworkManager::getInstance().end();
NetworkManager::getInstance().init(nrClient);
mainMessageBoxState=1;
Lang &lang= Lang::getInstance();
showMessageBox(lang.get("Couldnt connect"), lang.get("Connection failed"), false);
return;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] connection failed\n",__FILE__,__FUNCTION__);
}
else
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] connected ro [%s]\n",__FILE__,__FUNCTION__,serverIp.getString().c_str());
//save server ip
//config.setString("ServerIp", serverIp.getString());
//config.save();
mainMenu->setState(new MenuStateConnectedGame(program, mainMenu,jmMasterserver));
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
}
void MenuStateMasterserver::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);
}
}
}}//end namespace

View File

@@ -0,0 +1,97 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74>o 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
// ==============================================================
#ifndef _GLEST_GAME_MENUSTATEMASTERSERVER_H_
#define _GLEST_GAME_MENUSTATEMASTERSERVER_H_
#include "main_menu.h"
#include "masterserver_info.h"
namespace Glest{ namespace Game{
// ===============================
// ServerLine
// ===============================
class ServerLine {
private:
MasterServerInfo *masterServerInfo;
int index;
GraphicButton selectButton;
//general info:
GraphicLabel glestVersionLabel;
GraphicLabel platformLabel;
GraphicLabel binaryCompileDateLabel;
//game info:
GraphicLabel serverTitleLabel;
GraphicLabel ipAddressLabel;
//game setup info:
GraphicLabel techLabel;
GraphicLabel mapLabel;
GraphicLabel tilesetLabel;
GraphicLabel activeSlotsLabel;
public:
ServerLine( MasterServerInfo *mServerInfo, int lineIndex);
virtual ~ServerLine();
MasterServerInfo *getMasterServerInfo() const {return masterServerInfo;}
const int getIndex() const {return index;}
bool buttonMouseClick(int x, int y);
bool buttonMouseMove(int x, int y);
//void setIndex(int value);
void render();
};
// ===============================
// class MenuStateMasterserver
// ===============================
typedef vector<ServerLine*> ServerLines;
typedef vector<MasterServerInfo*> MasterServerInfos;
class MenuStateMasterserver: public MenuState{
private:
GraphicButton buttonRefresh;
GraphicButton buttonReturn;
GraphicLabel labelTitle;
ServerLines serverLines;
GraphicMessageBox mainMessageBox;
int mainMessageBoxState;
public:
MenuStateMasterserver(Program *program, MainMenu *mainMenu);
virtual ~MenuStateMasterserver();
void mouseClick(int x, int y, MouseButton mouseButton);
void mouseMove(int x, int y, const MouseState *mouseState);
void update();
void render();
private:
void showMessageBox(const string &text, const string &header, bool toggle);
void connectToServer(string ipString);
void clearServerLines();
void updateServerInfo();
};
}}//end namespace
#endif

View File

@@ -0,0 +1,130 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74>o 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 "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
// =====================================================
MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu):
MenuState(program, mainMenu, "root")
{
Lang &lang= Lang::getInstance();
int i=390;
buttonNewGame.init(425, i, 150);
i-=40;
buttonJoinGame.init(425, i, 150);
i-=40;
buttonMasterserverGame.init(425, i, 150);
i-=40;
buttonOptions.init(425, i, 150);
i-=40;
buttonAbout.init(425, i , 150);
i-=40;
buttonExit.init(425, i, 150);
labelVersion.init(525, 420);
buttonNewGame.setText(lang.get("NewGame"));
buttonJoinGame.setText(lang.get("JoinGame"));
buttonMasterserverGame.setText(lang.get("JoinInternetGame(work in progress!!)"));
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(buttonMasterserverGame.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundB());
mainMenu->setState(new MenuStateMasterserver(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);
buttonMasterserverGame.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(&buttonMasterserverGame);
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

View File

@@ -0,0 +1,45 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74>o 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
// ==============================================================
#ifndef _GLEST_GAME_MENUSTATEROOT_H_
#define _GLEST_GAME_MENUSTATEROOT_H_
#include "main_menu.h"
namespace Glest{ namespace Game{
// ===============================
// class MenuStateRoot
// ===============================
class MenuStateRoot: public MenuState{
private:
GraphicButton buttonNewGame;
GraphicButton buttonJoinGame;
GraphicButton buttonMasterserverGame;
GraphicButton buttonOptions;
GraphicButton buttonAbout;
GraphicButton buttonExit;
GraphicLabel labelVersion;
public:
MenuStateRoot(Program *program, MainMenu *mainMenu);
void mouseClick(int x, int y, MouseButton mouseButton);
void mouseMove(int x, int y, const MouseState *mouseState);
void render();
void update();
};
}}//end namespace
#endif

View File

@@ -0,0 +1,83 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o 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
// ==============================================================
#ifndef _GLEST_GAME_MASTERSERVERINFO_H_
#define _GLEST_GAME_MASTERSERVERINFO_H_
#include <string>
using std::string;
namespace Glest{ namespace Game{
// ===========================================================
// class ParticleSystemType
//
/// A type of particle system
// ===========================================================
class MasterServerInfo{
protected:
//general info:
string glestVersion;
string platform;
string binaryCompileDate;
//game info:
string serverTitle;
string ipAddress;
//game setup info:
string tech;
string map;
string tileset;
int activeSlots;
int networkSlots;
int connectedClients;
public:
const string &getGlestVersion() const {return glestVersion;}
const string &getPlatform() const {return platform;}
const string &getBinaryCompileDate() const {return binaryCompileDate;}
const string &getServerTitle() const {return serverTitle;}
const string &getIpAddress() const {return ipAddress;}
const string &getTech() const {return tech;}
const string &getMap() const {return map;}
const string &getTileset() const {return tileset;}
const int getActiveSlots() const {return activeSlots;}
const int getNetworkSlots() const {return networkSlots;}
const int getConnectedClients() const {return connectedClients;}
//general info:
void setGlestVersion(string value) { glestVersion = value; }
void setPlatform(string value) { platform = value; }
void setBinaryCompileDate(string value) { binaryCompileDate = value; }
//game info:
void setServerTitle(string value) { serverTitle = value; }
void setIpAddress(string value) { ipAddress = value; }
//game setup info:
void setTech(string value) { tech = value; }
void setMap(string value) { map = value; }
void setTileset(string value) { tileset = value; }
void setActiveSlots(int value) { activeSlots = value; }
void setNetworkSlots(int value) { networkSlots = value; }
void setConnectedClients(int value) { connectedClients = value; }
};
}}//end namespace
#endif