Network Playernames ( and some more changes in the options menu )

This commit is contained in:
Titus Tscharntke 2010-03-23 01:38:19 +00:00
parent c26e924e8c
commit 397fe3dc41
6 changed files with 197 additions and 56 deletions

View File

@ -30,6 +30,7 @@ FontDisplay=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
FontMenu=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
Lang=english
MaxLights=1
NetPlayerName=unknown
NetworkConsistencyChecks=true
PhotoMode=false
RefreshFrequency=75

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -13,6 +13,7 @@
#include "window.h"
#include "console.h"
#include "config.h"
#include "network_manager.h"
#include "lang.h"
#include "util.h"
@ -63,8 +64,9 @@ void ChatManager::keyDown(char key){
editEnabled= false;
if(!text.empty()){
console->addLine(gameNetworkInterface->getHostName() + ": " + text);
gameNetworkInterface->sendTextMessage(text, teamMode? thisTeamIndex: -1);
console->addLine(Config::getInstance().getString("NetPlayerName") + ": " + text);
gameNetworkInterface->sendTextMessage(Config::getInstance().getString("NetPlayerName")+": "+
text, teamMode? thisTeamIndex: -1);
}
}
else{
@ -93,6 +95,7 @@ void ChatManager::updateNetwork()
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
string text;
string sender;
Config &config= Config::getInstance();
if(!gameNetworkInterface->getChatText().empty())
{
@ -101,7 +104,7 @@ void ChatManager::updateNetwork()
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] got nmtText [%s] for team = %d\n",__FILE__,__FUNCTION__,gameNetworkInterface->getChatText().c_str(),teamIndex);
if(teamIndex==-1 || teamIndex==thisTeamIndex){
console->addLine(gameNetworkInterface->getChatSender()+": "+gameNetworkInterface->getChatText(), true);
console->addLine(gameNetworkInterface->getChatText(), true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__);
}

View File

@ -33,10 +33,12 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
{
Lang &lang= Lang::getInstance();
Config &config= Config::getInstance();
activeInputLabel=NULL;
//create
buttonReturn.init(200, 150, 125);
buttonAutoConfig.init(375, 150, 125);
buttonOk.init(200, 150, 100);
buttonAbort.init(310, 150, 100);
buttonAutoConfig.init(450, 150, 125);
//labels
labelVolumeFx.init(200, 530);
@ -44,6 +46,8 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelVolumeMusic.init(200, 470);
labelLang.init(200, 400);
labelPlayerNameLabel.init(200,370);
labelPlayerName.init(350,370);
labelFilter.init(200, 340);
labelShadows.init(200, 310);
@ -66,9 +70,11 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
listBoxUnitParticles.init(350,220,80);
//set text
buttonReturn.setText(lang.get("Return"));
buttonOk.setText(lang.get("Ok"));
buttonAbort.setText(lang.get("Abort"));
buttonAutoConfig.setText(lang.get("AutoConfig"));
labelLang.setText(lang.get("Language"));
labelPlayerNameLabel.setText(lang.get("Playername"));
labelShadows.setText(lang.get("Shadows"));
labelFilter.setText(lang.get("Filter"));
labelTextures3D.setText(lang.get("Textures3D"));
@ -89,6 +95,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
listBoxLang.setItems(langResults);
listBoxLang.setSelectedItem(config.getString("Lang"));
//playerName
labelPlayerName.setText(config.getString("NetPlayerName"));
//shadows
for(int i= 0; i<Renderer::sCount; ++i){
listBoxShadows.pushBackItem(lang.get(Renderer::shadowsToStr(static_cast<Renderer::Shadows>(i))));
@ -127,16 +136,21 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
listBoxVolumeFx.setSelectedItem(intToStr(config.getInt("SoundVolumeFx")/5*5));
listBoxVolumeAmbient.setSelectedItem(intToStr(config.getInt("SoundVolumeAmbient")/5*5));
listBoxVolumeMusic.setSelectedItem(intToStr(config.getInt("SoundVolumeMusic")/5*5));
}
void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
Config &config= Config::getInstance();
Lang &lang= Lang::getInstance();
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
if(buttonReturn.mouseClick(x, y)){
if(buttonOk.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundA());
saveConfig();
mainMenu->setState(new MenuStateRoot(program, mainMenu));
}
else if(buttonAbort.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundA());
mainMenu->setState(new MenuStateRoot(program, mainMenu));
}
@ -145,54 +159,27 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
Renderer::getInstance().autoConfig();
saveConfig();
mainMenu->setState(new MenuStateOptions(program, mainMenu));
}
else if(labelPlayerName.mouseClick(x, y) && ( activeInputLabel != &labelPlayerName )){
setActiveInputLable(&labelPlayerName);
}
else if(listBoxLang.mouseClick(x, y)){
config.setString("Lang", listBoxLang.getSelectedItem());
lang.loadStrings(config.getString("Lang"));
saveConfig();
mainMenu->setState(new MenuStateOptions(program, mainMenu));
else
{
listBoxLang.mouseClick(x, y);
listBoxShadows.mouseClick(x, y);
listBoxFilter.mouseClick(x, y);
listBoxTextures3D.mouseClick(x, y);
listBoxUnitParticles.mouseClick(x, y);
listBoxLights.mouseClick(x, y);
listBoxVolumeFx.mouseClick(x, y);
listBoxVolumeAmbient.mouseClick(x, y);
listBoxVolumeMusic.mouseClick(x, y);
}
else if(listBoxShadows.mouseClick(x, y)){
int index= listBoxShadows.getSelectedItemIndex();
config.setString("Shadows", Renderer::shadowsToStr(static_cast<Renderer::Shadows>(index)));
saveConfig();
}
else if(listBoxFilter.mouseClick(x, y)){
config.setString("Filter", listBoxFilter.getSelectedItem());
saveConfig();
}
else if(listBoxTextures3D.mouseClick(x, y)){
config.setInt("Textures3D", listBoxTextures3D.getSelectedItemIndex());
saveConfig();
}
else if(listBoxUnitParticles.mouseClick(x, y)){
config.setBool("UnitParticles", listBoxUnitParticles.getSelectedItemIndex());
saveConfig();
}
else if(listBoxLights.mouseClick(x, y)){
config.setInt("MaxLights", listBoxLights.getSelectedItemIndex()+1);
saveConfig();
}
else if(listBoxVolumeFx.mouseClick(x, y)){
config.setString("SoundVolumeFx", listBoxVolumeFx.getSelectedItem());
saveConfig();
}
else if(listBoxVolumeAmbient.mouseClick(x, y)){
config.setString("SoundVolumeAmbient", listBoxVolumeAmbient.getSelectedItem());
saveConfig();
}
else if(listBoxVolumeMusic.mouseClick(x, y)){
CoreData::getInstance().getMenuMusic()->setVolume(strToInt(listBoxVolumeMusic.getSelectedItem())/100.f);
config.setString("SoundVolumeMusic", listBoxVolumeMusic.getSelectedItem());
saveConfig();
}
}
void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){
buttonReturn.mouseMove(x, y);
buttonOk.mouseMove(x, y);
buttonAbort.mouseMove(x, y);
buttonAutoConfig.mouseMove(x, y);
listBoxLang.mouseMove(x, y);
listBoxVolumeFx.mouseMove(x, y);
@ -206,10 +193,41 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){
listBoxLights.mouseMove(x, y);
}
void MenuStateOptions::keyDown(char key){
if(activeInputLabel!=NULL)
{
if(key==vkBack){
string text= activeInputLabel->getText();
if(text.size()>1){
text.erase(text.end()-2);
}
activeInputLabel->setText(text);
}
}
}
void MenuStateOptions::keyPress(char c){
if(activeInputLabel!=NULL)
{
int maxTextSize= 16;
if(&labelPlayerName==activeInputLabel){
if((c>='0' && c<='9')||(c>='a' && c<='z')||(c>='A' && c<='Z')||
(c=='-')||(c=='(')||(c==')')){
if(activeInputLabel->getText().size()<maxTextSize){
string text= activeInputLabel->getText();
text.insert(text.end()-1, c);
activeInputLabel->setText(text);
}
}
}
}
}
void MenuStateOptions::render(){
Renderer &renderer= Renderer::getInstance();
renderer.renderButton(&buttonReturn);
renderer.renderButton(&buttonOk);
renderer.renderButton(&buttonAbort);
renderer.renderButton(&buttonAutoConfig);
renderer.renderListBox(&listBoxLang);
renderer.renderListBox(&listBoxShadows);
@ -221,6 +239,8 @@ void MenuStateOptions::render(){
renderer.renderListBox(&listBoxVolumeAmbient);
renderer.renderListBox(&listBoxVolumeMusic);
renderer.renderLabel(&labelLang);
renderer.renderLabel(&labelPlayerNameLabel);
renderer.renderLabel(&labelPlayerName);
renderer.renderLabel(&labelShadows);
renderer.renderLabel(&labelTextures3D);
renderer.renderLabel(&labelUnitParticles);
@ -233,10 +253,57 @@ void MenuStateOptions::render(){
void MenuStateOptions::saveConfig(){
Config &config= Config::getInstance();
Lang &lang= Lang::getInstance();
setActiveInputLable(NULL);
if(labelPlayerName.getText().length()>0)
{
config.setString("NetPlayerName", labelPlayerName.getText());
}
//Copy values
config.setString("Lang", listBoxLang.getSelectedItem());
lang.loadStrings(config.getString("Lang"));
int index= listBoxShadows.getSelectedItemIndex();
config.setString("Shadows", Renderer::shadowsToStr(static_cast<Renderer::Shadows>(index)));
config.setString("Filter", listBoxFilter.getSelectedItem());
config.setInt("Textures3D", listBoxTextures3D.getSelectedItemIndex());
config.setBool("UnitParticles", listBoxUnitParticles.getSelectedItemIndex());
config.setInt("MaxLights", listBoxLights.getSelectedItemIndex()+1);
config.setString("SoundVolumeFx", listBoxVolumeFx.getSelectedItem());
config.setString("SoundVolumeAmbient", listBoxVolumeAmbient.getSelectedItem());
CoreData::getInstance().getMenuMusic()->setVolume(strToInt(listBoxVolumeMusic.getSelectedItem())/100.f);
config.setString("SoundVolumeMusic", listBoxVolumeMusic.getSelectedItem());
config.save();
Renderer::getInstance().loadConfig();
SoundRenderer::getInstance().loadConfig();
}
void MenuStateOptions::setActiveInputLable(GraphicLabel *newLable)
{
if(newLable!=NULL){
string text= newLable->getText();
size_t found;
found=text.find_last_of("_");
if (found==string::npos)
{
text=text+"_";
}
newLable->setText(text);
}
if(activeInputLabel!=NULL && !activeInputLabel->getText().empty()){
string text= activeInputLabel->getText();
size_t found;
found=text.find_last_of("_");
if (found!=string::npos)
{
text=text.substr(0,found);
}
activeInputLabel->setText(text);
}
activeInputLabel=newLable;
}
}}//end namespace

View File

@ -0,0 +1,70 @@
// ==============================================================
// 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_MENUSTATEOPTIONS_H_
#define _GLEST_GAME_MENUSTATEOPTIONS_H_
#include "main_menu.h"
namespace Glest{ namespace Game{
// ===============================
// class MenuStateOptions
// ===============================
class MenuStateOptions: public MenuState{
private:
GraphicButton buttonOk;
GraphicButton buttonAbort;
GraphicButton buttonAutoConfig;
GraphicLabel labelLang;
GraphicLabel labelShadows;
GraphicLabel labelFilter;
GraphicLabel labelTextures3D;
GraphicLabel labelLights;
GraphicLabel labelUnitParticles;
GraphicLabel labelVolumeFx;
GraphicLabel labelVolumeAmbient;
GraphicLabel labelVolumeMusic;
GraphicListBox listBoxLang;
GraphicListBox listBoxShadows;
GraphicListBox listBoxFilter;
GraphicListBox listBoxTextures3D;
GraphicListBox listBoxLights;
GraphicListBox listBoxUnitParticles;
GraphicListBox listBoxVolumeFx;
GraphicListBox listBoxVolumeAmbient;
GraphicListBox listBoxVolumeMusic;
GraphicListBox listBoxMusicSelect;
GraphicLabel labelPlayerName;
GraphicLabel labelPlayerNameLabel;
GraphicLabel *activeInputLabel;
public:
MenuStateOptions(Program *program, MainMenu *mainMenu);
void mouseClick(int x, int y, MouseButton mouseButton);
void mouseMove(int x, int y, const MouseState *mouseState);
void render();
virtual void keyDown(char key);
virtual void keyPress(char c);
private:
void saveConfig();
void setActiveInputLable(GraphicLabel* newLable);
};
}}//end namespace
#endif

View File

@ -160,7 +160,7 @@ void ClientInterface::updateLobby()
//send intro message
NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), getHostName(), -1);
NetworkMessageIntro sendNetworkMessageIntro(getNetworkVersionString(), Config::getInstance().getString("NetPlayerName"), -1);
playerIndex= networkMessageIntro.getPlayerIndex();
serverName= networkMessageIntro.getName();

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martińo Figueroa
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -349,7 +349,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum){
}
void ServerInterface::sendTextMessage(const string &text, int teamIndex){
NetworkMessageText networkMessageText(text, getHostName(), teamIndex);
NetworkMessageText networkMessageText(text, Config::getInstance().getString("NetPlayerName"), teamIndex);
broadcastMessage(&networkMessageText);
}