internet menu updated ( work in progress ) ; checkboxes ; lines

This commit is contained in:
Titus Tscharntke 2010-12-27 00:59:57 +00:00
parent 81783e3f1b
commit 36c4b4c5fa
17 changed files with 824 additions and 320 deletions

View File

@ -302,6 +302,12 @@ void GraphicListBox::setSelectedItemIndex(int index, bool errorOnMissing){
setText(getSelectedItem());
}
void GraphicListBox::setY(int y) {
this->y= y;
graphButton1.setY(y);
graphButton2.setY(y);
}
void GraphicListBox::setEditable(bool editable){
graphButton1.setEditable(editable);
graphButton2.setEditable(editable);
@ -460,4 +466,49 @@ bool GraphicMessageBox::mouseClick(int x, int y, int &clickedButton){
return false;
}
// =====================================================
// class GraphicLine
// =====================================================
const int GraphicLine::defH= 5;
const int GraphicLine::defW= 1000;
void GraphicLine::init(int x, int y, int w, int h){
GraphicComponent::init(x, y, w, h);
horizontal=true;
}
// =====================================================
// class GraphicCheckBox
// =====================================================
const int GraphicCheckBox::defH= 22;
const int GraphicCheckBox::defW= 22;
void GraphicCheckBox::init(int x, int y, int w, int h){
GraphicComponent::init(x, y, w, h);
value=true;
lighted= false;
}
bool GraphicCheckBox::mouseMove(int x, int y){
if(this->getVisible() == false) {
return false;
}
bool b= GraphicComponent::mouseMove(x, y);
lighted= b;
return b;
}
bool GraphicCheckBox::mouseClick(int x, int y){
bool result=GraphicComponent::mouseClick( x, y);
if(result)
if(value)
value=false;
else
value=true;
return result;
}
}}//end namespace

View File

@ -168,6 +168,7 @@ public:
void setSelectedItemIndex(int index, bool errorOnMissing=true);
void setSelectedItem(string item, bool errorOnMissing=true);
void setEditable(bool editable);
virtual void setY(int y);
virtual bool mouseMove(int x, int y);
virtual bool mouseClick(int x, int y);
@ -207,6 +208,46 @@ public:
bool mouseClick(int x, int y, int &clickedButton);
};
}}//end namespace
// ===========================================================
// class GraphicLine
// ===========================================================
class GraphicLine: public GraphicComponent {
public:
static const int defH;
static const int defW;
private:
bool horizontal;
public:
void init(int x, int y, int w=defW, int h=defH);
bool getHorizontal() const {return horizontal;}
void setHorizontal(bool horizontal) {this->horizontal= horizontal;}
};
// ===========================================================
// class GraphicCheckBox
// ===========================================================
class GraphicCheckBox: public GraphicComponent {
public:
static const int defH;
static const int defW;
private:
bool value;
bool lighted;
public:
void init(int x, int y, int w=defW, int h=defH);
bool getValue() const {return value;}
void setValue(bool value) {this->value= value;}
bool getLighted() const {return lighted;}
void setLighted(bool lighted) {this->lighted= lighted;}
virtual bool mouseMove(int x, int y);
virtual bool mouseClick(int x, int y);
};
}}//end namespace
#endif

View File

@ -16,6 +16,7 @@
#include "config.h"
#include "network_manager.h"
#include "lang.h"
#include "core_data.h"
#include "util.h"
#include <stdexcept>
#include "leak_dumper.h"
@ -30,14 +31,16 @@ namespace Glest{ namespace Game{
// class ChatManager
// =====================================================
const int ChatManager::maxTextLenght= 64;
ChatManager::ChatManager() {
console= NULL;
editEnabled= false;
teamMode= false;
thisTeamIndex= -1;
disableTeamMode = false;
xPos=300;
yPos=150;
maxTextLenght=64;
font=CoreData::getInstance().getConsoleFont();
}
void ChatManager::init(Console* console, int thisTeamIndex, const bool inMenu, string manualPlayerNameOverride) {
@ -141,8 +144,7 @@ void ChatManager::keyDown(char key) {
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key);
editEnabled= true;
text.clear();
switchOnEdit();
}
}
}
@ -165,6 +167,11 @@ void ChatManager::keyDown(char key) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void ChatManager::switchOnEdit(){
editEnabled= true;
text.clear();
}
void ChatManager::keyPress(char c){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c,c);
@ -177,6 +184,12 @@ void ChatManager::keyPress(char c){
}
}
void ChatManager::addText(string text){
if(editEnabled && text.size()+this->text.size()<maxTextLenght){
this->text+= text;
}
}
void ChatManager::updateNetwork() {
try {
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();

View File

@ -13,9 +13,11 @@
#define _GLEST_GAME_CHATMANAGER_H_
#include <string>
#include "font.h"
#include "leak_dumper.h"
using std::string;
using Shared::Graphics::Font2D;
namespace Glest{ namespace Game{
@ -26,8 +28,6 @@ class Console;
// =====================================================
class ChatManager{
private:
static const int maxTextLenght;
private:
bool editEnabled;
@ -38,6 +38,11 @@ private:
int thisTeamIndex;
bool inMenu;
string manualPlayerNameOverride;
int xPos;
int yPos;
int maxTextLenght;
Font2D *font;
public:
ChatManager();
@ -51,6 +56,17 @@ public:
bool getEditEnabled() const {return editEnabled;}
bool getTeamMode() const {return teamMode;}
string getText() const {return text;}
int getXPos() const {return xPos;}
void setXPos(int xPos) {this->xPos= xPos;}
int getYPos() const {return yPos;}
void setYPos(int yPos) {this->yPos= yPos;}
int getMaxTextLenght() const {return maxTextLenght;}
void setMaxTextLenght(int maxTextLenght) {this->maxTextLenght= maxTextLenght;}
Font2D *getFont() const {return font;}
void setFont(Font2D *font) {this->font= font;}
void addText(string text);
void switchOnEdit();
bool getDisableTeamMode() const { return disableTeamMode; }
void setDisableTeamMode(bool value);

View File

@ -35,6 +35,10 @@ Console::Console() {
maxStoredLines = Config::getInstance().getInt("ConsoleMaxLinesStored");
timeout = Config::getInstance().getInt("ConsoleTimeout");
timeElapsed = 0.0f;
xPos=20;
yPos=20;
lineHeight=20;
font=CoreData::getInstance().getConsoleFont();
}
void Console::addStdMessage(const string &s) {

View File

@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include <stdexcept>
#include "font.h"
#include "leak_dumper.h"
using std::string;
@ -25,6 +26,8 @@ using namespace std;
namespace Glest { namespace Game {
using Shared::Graphics::Font2D;
// =====================================================
// class Console
//
@ -57,12 +60,25 @@ private:
int maxLines;
int maxStoredLines;
float timeout;
int xPos;
int yPos;
int lineHeight;
Font2D *font;
public:
Console();
int getStoredLineCount() const {return storedLines.size();}
int getLineCount() const {return lines.size();}
int getXPos() const {return xPos;}
void setXPos(int xPos) {this->xPos= xPos;}
int getYPos() const {return yPos;}
void setYPos(int yPos) {this->yPos= yPos;}
int getLineHeight() const {return lineHeight;}
void setLineHeight(int lineHeight) {this->lineHeight= lineHeight;}
Font2D *getFont() const {return font;}
void setFont(Font2D *font) {this->font= font;}
string getLine(int i) const;
string getStoredLine(int i) const;
ConsoleLineInfo getLineItem(int i) const;

View File

@ -100,6 +100,29 @@ void CoreData::load() {
buttonBigTexture->setForceCompressionDisabled(true);
buttonBigTexture->getPixmap()->load(dir+"/menu/textures/button_big.tga");
horizontalLineTexture= renderer.newTexture2D(rsGlobal);
horizontalLineTexture->setForceCompressionDisabled(true);
horizontalLineTexture->getPixmap()->load(dir+"/menu/textures/line_horizontal.tga");
verticalLineTexture= renderer.newTexture2D(rsGlobal);
verticalLineTexture->setForceCompressionDisabled(true);
verticalLineTexture->getPixmap()->load(dir+"/menu/textures/line_vertical.tga");
checkBoxTexture= renderer.newTexture2D(rsGlobal);
checkBoxTexture->setForceCompressionDisabled(true);
checkBoxTexture->getPixmap()->load(dir+"/menu/textures/checkbox.tga");
checkedCheckBoxTexture= renderer.newTexture2D(rsGlobal);
checkedCheckBoxTexture->setForceCompressionDisabled(true);
checkedCheckBoxTexture->getPixmap()->load(dir+"/menu/textures/checkbox_checked.tga");
Texture2D *horizontalLineTexture;
Texture2D *verticalLineTexture;
Texture2D *checkBoxTexture;
Texture2D *checkedCeckBoxTextur;
//display font
Config &config= Config::getInstance();
string displayFontNamePrefix=config.getString("FontDisplayPrefix");

View File

@ -53,6 +53,10 @@ private:
Texture2D *customTexture;
Texture2D *buttonSmallTexture;
Texture2D *buttonBigTexture;
Texture2D *horizontalLineTexture;
Texture2D *verticalLineTexture;
Texture2D *checkBoxTexture;
Texture2D *checkedCheckBoxTexture;
Font2D *displayFont;
Font2D *menuFontNormal;
@ -75,6 +79,10 @@ public:
Texture2D *getCustomTexture() const {return customTexture;}
Texture2D *getButtonSmallTexture() const {return buttonSmallTexture;}
Texture2D *getButtonBigTexture() const {return buttonBigTexture;}
Texture2D *getHorizontalLineTexture() const {return horizontalLineTexture;}
Texture2D *getVerticalLineTexture() const {return verticalLineTexture;}
Texture2D *getCheckBoxTexture() const {return checkBoxTexture;}
Texture2D *getCheckedCheckBoxTexture() const {return checkedCheckBoxTexture;}
size_t getLogoTextureExtraCount() const {return logoTextureList.size();}
Texture2D *getLogoTextureExtra(int idx) const {return logoTextureList[idx];}

View File

@ -835,8 +835,12 @@ void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *te
assertGl();
}
void Renderer::RenderConsoleLine(int lineIndex, int xPosition, const ConsoleLineInfo *lineInfo) {
void Renderer::renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight,
const Font2D* font, const ConsoleLineInfo *lineInfo) {
Vec4f fontColor;
const Metrics &metrics= Metrics::getInstance();
const FontMetrics *fontMetrics= font->getMetrics();
if(game != NULL) {
fontColor = game->getGui()->getDisplay()->getColor();
}
@ -866,18 +870,15 @@ void Renderer::RenderConsoleLine(int lineIndex, int xPosition, const ConsoleLine
//string headerLine = "*" + playerName + ":";
string headerLine = playerName + ": ";
const Metrics &metrics= Metrics::getInstance();
const FontMetrics *fontMetrics= CoreData::getInstance().getConsoleFont()->getMetrics();
if(fontMetrics == NULL) {
throw runtime_error("fontMetrics == NULL");
}
renderTextShadow(
headerLine,
CoreData::getInstance().getConsoleFont(),
headerLine,
font,
fontColor,
xPosition, lineIndex * 20 + 20);
xPosition, lineIndex * lineHeight + yPosition);
fontColor = defaultFontColor;
//xPosition += (8 * (playerName.length() + 2));
@ -889,18 +890,15 @@ void Renderer::RenderConsoleLine(int lineIndex, int xPosition, const ConsoleLine
string playerName = lineInfo->originalPlayerName;
string headerLine = playerName + ": ";
const Metrics &metrics= Metrics::getInstance();
const FontMetrics *fontMetrics= CoreData::getInstance().getConsoleFont()->getMetrics();
if(fontMetrics == NULL) {
throw runtime_error("fontMetrics == NULL");
}
renderTextShadow(
headerLine,
CoreData::getInstance().getConsoleFont(),
headerLine,
font,
fontColor,
xPosition, lineIndex * 20 + 20);
xPosition, lineIndex * lineHeight + yPosition);
fontColor = defaultFontColor;
//xPosition += (8 * (playerName.length() + 2));
@ -913,13 +911,12 @@ void Renderer::RenderConsoleLine(int lineIndex, int xPosition, const ConsoleLine
renderTextShadow(
lineInfo->text,
CoreData::getInstance().getConsoleFont(),
font,
fontColor,
xPosition, lineIndex * 20 + 20);
xPosition, (lineIndex * lineHeight) + yPosition);
}
void Renderer::renderConsole(const Console *console,const bool showFullConsole,const bool showMenuConsole){
if(console == NULL) {
throw runtime_error("console == NULL");
}
@ -929,23 +926,23 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,c
if(showFullConsole) {
for(int i = 0; i < console->getStoredLineCount(); ++i) {
int xPosition = 20;
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
RenderConsoleLine(i, xPosition, &lineInfo);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), &lineInfo);
}
}
else if(showMenuConsole) {
for(int i = 0; i < console->getStoredLineCount() && i < maxConsoleLines; ++i) {
int xPosition = 20;
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
RenderConsoleLine(i, xPosition, &lineInfo);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), &lineInfo);
}
}
else {
for(int i = 0; i < console->getLineCount(); ++i) {
int xPosition = 20;
const ConsoleLineInfo &lineInfo = console->getLineItem(i);
RenderConsoleLine(i, xPosition, &lineInfo);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), &lineInfo);
}
}
glPopAttrib();
@ -976,9 +973,9 @@ void Renderer::renderChatManager(const ChatManager *chatManager) {
renderTextShadow(
text,
CoreData::getInstance().getConsoleFont(),
chatManager->getFont(),
fontColor,
300, 150);
chatManager->getXPos(), chatManager->getYPos());
//textRenderer->begin(CoreData::getInstance().getConsoleFont());
//textRenderer->render(text, 300, 150);
@ -1309,6 +1306,142 @@ void Renderer::renderButton(const GraphicButton *button) {
glPopAttrib();
}
void Renderer::renderCheckBox(const GraphicCheckBox *box) {
if(box->getVisible() == false) {
return;
}
int x= box->getX();
int y= box->getY();
int h= box->getH();
int w= box->getW();
const Vec3f disabledTextColor= Vec3f(0.25f,0.25f,0.25f);
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
//background
CoreData &coreData= CoreData::getInstance();
Texture2D *backTexture= box->getValue()? coreData.getCheckedCheckBoxTexture(): coreData.getCheckBoxTexture();
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, static_cast<Texture2DGl*>(backTexture)->getHandle());
//box
Vec4f fontColor;
//if(game!=NULL){
// fontColor=game->getGui()->getDisplay()->getColor();
// fontColor.w = GraphicComponent::getFade();
//}
//else {
// white shadowed is default ( in the menu for example )
fontColor=Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade());
//}
//Vec4f color= Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade());
Vec4f color= fontColor;
glColor4fv(color.ptr());
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.f, 0.f);
glVertex2f(x, y);
glTexCoord2f(0.f, 1.f);
glVertex2f(x, y+h);
glTexCoord2f(1.f, 0.f);
glVertex2f(x+w, y);
glTexCoord2f(1.f, 1.f);
glVertex2f(x+w, y+h);
glEnd();
glDisable(GL_TEXTURE_2D);
//lighting
float anim= GraphicComponent::getAnim();
if(anim>0.5f) anim= 1.f-anim;
if(box->getLighted() && box->getEditable()){
const int lightSize= 0;
const Vec4f color1= Vec4f(color.x, color.y, color.z, 0.1f+anim*0.5f);
const Vec4f color2= Vec4f(color.x, color.y, color.z, 0.3f+anim);
glBegin(GL_TRIANGLE_FAN);
glColor4fv(color2.ptr());
glVertex2f(x+w/2, y+h/2);
glColor4fv(color1.ptr());
glVertex2f(x-lightSize, y-lightSize);
glColor4fv(color1.ptr());
glVertex2f(x+w+lightSize, y-lightSize);
glColor4fv(color1.ptr());
glVertex2f(x+w+lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f(x+w+lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f(x-lightSize, y+h+lightSize);
glColor4fv(color1.ptr());
glVertex2f(x-lightSize, y-lightSize);
glEnd();
}
glPopAttrib();
}
void Renderer::renderLine(const GraphicLine *line) {
if(line->getVisible() == false) {
return;
}
int x= line->getX();
int y= line->getY();
int h= line->getH();
int w= line->getW();
const Vec3f disabledTextColor= Vec3f(0.25f,0.25f,0.25f);
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
//background
CoreData &coreData= CoreData::getInstance();
Texture2D *backTexture= line->getHorizontal()? coreData.getHorizontalLineTexture(): coreData.getVerticalLineTexture();
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, static_cast<Texture2DGl*>(backTexture)->getHandle());
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.f, 0.f);
glVertex2f(x, y);
glTexCoord2f(0.f, 1.f);
glVertex2f(x, y+h);
glTexCoord2f(1.f, 0.f);
glVertex2f(x+w, y);
glTexCoord2f(1.f, 1.f);
glVertex2f(x+w, y+h);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopAttrib();
}
void Renderer::renderListBox(const GraphicListBox *listBox) {
if(listBox->getVisible() == false) {
return;

View File

@ -312,7 +312,7 @@ public:
void renderBackground(const Texture2D *texture);
void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL);
void renderConsole(const Console *console, const bool showAll=false, const bool showMenuConsole=false);
void RenderConsoleLine(int lineIndex, int xPosition, const ConsoleLineInfo *lineInfo);
void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, const Font2D* font,const ConsoleLineInfo *lineInfo);
void renderChatManager(const ChatManager *chatManager);
void renderResourceStatus();
void renderSelectionQuad();
@ -326,6 +326,8 @@ public:
void renderLabel(const GraphicLabel *label,const Vec3f *color);
void renderLabel(const GraphicLabel *label,const Vec4f *color);
void renderButton(const GraphicButton *button);
void renderCheckBox(const GraphicCheckBox *box);
void renderLine(const GraphicLine *line);
void renderListBox(const GraphicListBox *listBox);
void renderMessageBox(const GraphicMessageBox *listBox);

View File

@ -219,6 +219,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
listBoxTileset.registerGraphicComponent(containerName,"listBoxTileset");
listBoxTileset.init(xoffset+460, mapPos, 150);
listBoxTileset.setItems(results);
srand(time(NULL));
listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount());
labelTileset.registerGraphicComponent(containerName,"labelTileset");
labelTileset.init(xoffset+460, mapHeadPos);

View File

@ -11,6 +11,7 @@
#include "menu_state_masterserver.h"
#include "server_line.h"
#include "renderer.h"
#include "sound_renderer.h"
#include "core_data.h"
@ -35,157 +36,6 @@ DisplayMessageFunction MenuStateMasterserver::pCB_DisplayMessage = NULL;
static const char *IRC_SERVER = "irc.freenode.net";
static const char *IRC_CHANNEL = "#megaglest-lobby";
// =====================================================
// class ServerLine
// =====================================================
ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, const char * containerName) {
this->containerName = containerName;
Lang &lang= Lang::getInstance();
index=lineIndex;
int lineOffset = 25 * lineIndex;
masterServerInfo = *mServerInfo;
int i=10;
int startOffset=600;
//general info:
i+=10;
glestVersionLabel.registerGraphicComponent(containerName,"glestVersionLabel" + intToStr(lineIndex));
registeredObjNameList.push_back("glestVersionLabel" + intToStr(lineIndex));
glestVersionLabel.init(i,startOffset-lineOffset);
glestVersionLabel.setText(masterServerInfo.getGlestVersion());
i+=80;
registeredObjNameList.push_back("platformLabel" + intToStr(lineIndex));
platformLabel.registerGraphicComponent(containerName,"platformLabel" + intToStr(lineIndex));
platformLabel.init(i,startOffset-lineOffset);
platformLabel.setText(masterServerInfo.getPlatform());
// i+=50;
// registeredObjNameList.push_back("binaryCompileDateLabel" + intToStr(lineIndex));
// binaryCompileDateLabel.registerGraphicComponent(containerName,"binaryCompileDateLabel" + intToStr(lineIndex));
// binaryCompileDateLabel.init(i,startOffset-lineOffset);
// binaryCompileDateLabel.setText(masterServerInfo.getBinaryCompileDate());
//game info:
i+=130;
registeredObjNameList.push_back("serverTitleLabel" + intToStr(lineIndex));
serverTitleLabel.registerGraphicComponent(containerName,"serverTitleLabel" + intToStr(lineIndex));
serverTitleLabel.init(i,startOffset-lineOffset);
serverTitleLabel.setText(masterServerInfo.getServerTitle());
i+=210;
registeredObjNameList.push_back("ipAddressLabel" + intToStr(lineIndex));
ipAddressLabel.registerGraphicComponent(containerName,"ipAddressLabel" + intToStr(lineIndex));
ipAddressLabel.init(i,startOffset-lineOffset);
ipAddressLabel.setText(masterServerInfo.getIpAddress());
//game setup info:
i+=100;
registeredObjNameList.push_back("techLabel" + intToStr(lineIndex));
techLabel.registerGraphicComponent(containerName,"techLabel" + intToStr(lineIndex));
techLabel.init(i,startOffset-lineOffset);
techLabel.setText(masterServerInfo.getTech());
i+=100;
registeredObjNameList.push_back("mapLabel" + intToStr(lineIndex));
mapLabel.registerGraphicComponent(containerName,"mapLabel" + intToStr(lineIndex));
mapLabel.init(i,startOffset-lineOffset);
mapLabel.setText(masterServerInfo.getMap());
i+=100;
registeredObjNameList.push_back("tilesetLabel" + intToStr(lineIndex));
tilesetLabel.registerGraphicComponent(containerName,"tilesetLabel" + intToStr(lineIndex));
tilesetLabel.init(i,startOffset-lineOffset);
tilesetLabel.setText(masterServerInfo.getTileset());
i+=100;
registeredObjNameList.push_back("activeSlotsLabel" + intToStr(lineIndex));
activeSlotsLabel.registerGraphicComponent(containerName,"activeSlotsLabel" + intToStr(lineIndex));
activeSlotsLabel.init(i,startOffset-lineOffset);
activeSlotsLabel.setText(intToStr(masterServerInfo.getActiveSlots())+"/"+intToStr(masterServerInfo.getNetworkSlots())+"/"+intToStr(masterServerInfo.getConnectedClients()));
i+=50;
registeredObjNameList.push_back("externalConnectPort" + intToStr(lineIndex));
externalConnectPort.registerGraphicComponent(containerName,"externalConnectPort" + intToStr(lineIndex));
externalConnectPort.init(i,startOffset-lineOffset);
externalConnectPort.setText(intToStr(masterServerInfo.getExternalConnectPort()));
i+=50;
registeredObjNameList.push_back("selectButton" + intToStr(lineIndex));
selectButton.registerGraphicComponent(containerName,"selectButton" + intToStr(lineIndex));
selectButton.init(i, startOffset-lineOffset, 30);
selectButton.setText(">");
//printf("glestVersionString [%s] masterServerInfo->getGlestVersion() [%s]\n",glestVersionString.c_str(),masterServerInfo->getGlestVersion().c_str());
bool compatible = checkVersionComptability(glestVersionString, masterServerInfo.getGlestVersion());
selectButton.setEnabled(compatible);
selectButton.setEditable(compatible);
registeredObjNameList.push_back("gameFull" + intToStr(lineIndex));
gameFull.registerGraphicComponent(containerName,"gameFull" + intToStr(lineIndex));
gameFull.init(i, startOffset-lineOffset);
gameFull.setText(lang.get("MGGameSlotsFull"));
gameFull.setEnabled(!compatible);
gameFull.setEditable(!compatible);
GraphicComponent::applyAllCustomProperties(containerName);
}
ServerLine::~ServerLine() {
GraphicComponent::clearRegisterGraphicComponent(containerName, registeredObjNameList);
//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();
bool joinEnabled = (masterServerInfo.getNetworkSlots() > masterServerInfo.getConnectedClients());
if(joinEnabled == true) {
selectButton.setEnabled(true);
selectButton.setVisible(true);
gameFull.setEnabled(false);
gameFull.setEditable(false);
renderer.renderButton(&selectButton);
}
else {
selectButton.setEnabled(false);
selectButton.setVisible(false);
gameFull.setEnabled(true);
gameFull.setEditable(true);
renderer.renderLabel(&gameFull);
}
//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);
renderer.renderLabel(&externalConnectPort);
}
// =====================================================
// class MenuStateMasterserver
// =====================================================
@ -200,6 +50,26 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
Lang &lang= Lang::getInstance();
//Configure ConsolePosition
consoleIRC.setYPos(60);
consoleIRC.setFont(CoreData::getInstance().getMenuFontNormal());
consoleIRC.setLineHeight(18);
serverLinesToRender=9;
serverLinesLineHeight=25;
serverLinesYBase=680;
userButtonsYBase=serverLinesYBase-(serverLinesToRender+2)*serverLinesLineHeight;
userButtonsHeight=20;
userButtonsWidth=150;
userButtonsLineHeight=userButtonsHeight+2;
userButtonsToRender=userButtonsYBase/userButtonsLineHeight;
userButtonsXBase=1000-userButtonsWidth;
lines[0].init(0, userButtonsYBase+serverLinesLineHeight);
lines[1].init(userButtonsXBase-5,0,5,userButtonsYBase+userButtonsLineHeight);
lines[1].setHorizontal(false);
autoRefreshTime=0;
playServerFoundSound=false;
announcementLoaded=false;
@ -222,9 +92,10 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
versionInfoLabel.init(10, 680);
versionInfoLabel.setFont(CoreData::getInstance().getMenuFontBig());
versionInfoLabel.setText("");
// header
labelTitle.registerGraphicComponent(containerName,"labelTitle");
labelTitle.init(330, 640);
labelTitle.init(330, serverLinesYBase+40);
labelTitle.setFont(CoreData::getInstance().getMenuFontBig());
labelTitle.setText(lang.get("AvailableServers"));
@ -235,17 +106,12 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
// bottom
int buttonPos=230;
labelChatUrl.registerGraphicComponent(containerName,"labelChatUrl");
labelChatUrl.init(150,buttonPos-50);
labelChatUrl.setFont(CoreData::getInstance().getMenuFontBig());
labelChatUrl.setText(lang.get("NoServerVisitChat")+": http://webchat.freenode.net/?channels=glest");
// Titles for current games - START
int lineIndex = 0;
int lineOffset=25*lineIndex;
int i=10;
int startOffset=623;
int startOffset=serverLinesYBase+23;
//general info:
i+=10;
glestVersionLabel.registerGraphicComponent(containerName,"glestVersionLabel");
@ -333,20 +199,14 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
autoRefreshTime=10*listBoxAutoRefresh.getSelectedItemIndex();
ircOnlinePeopleLabel.registerGraphicComponent(containerName,"ircOnlinePeopleLabel");
ircOnlinePeopleLabel.init(10,startOffset-lineOffset+30);
ircOnlinePeopleLabel.init(userButtonsXBase,userButtonsYBase);
ircOnlinePeopleLabel.setText("IRC People Online:");
ircOnlinePeopleListLabel.registerGraphicComponent(containerName,"ircOnlinePeopleListLabel");
ircOnlinePeopleListLabel.init(90,startOffset-lineOffset+30);
ircOnlinePeopleListLabel.setText("n/a");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
NetworkManager::getInstance().end();
NetworkManager::getInstance().init(nrClient);
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
//console.addLine(lang.get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
GraphicComponent::applyAllCustomProperties(containerName);
@ -354,10 +214,15 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
char szIRCNick[80]="";
srand(time(NULL));
int randomNickId = rand() % 999;
sprintf(szIRCNick,"MG_%s_%d",Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()).c_str(),randomNickId);
string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
string ircname=netPlayerName.substr(0,9);
sprintf(szIRCNick,"MG_%s_%d",ircname.c_str(),randomNickId);
consoleIRC.addLine(lang.get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
lines[2].init(0,consoleIRC.getYPos()-10,userButtonsXBase,5);
chatManager.init(&consoleIRC, -1, true, szIRCNick);
chatManager.setXPos(0);
chatManager.setYPos(consoleIRC.getYPos()-20);
chatManager.setFont(CoreData::getInstance().getMenuFontNormal());
MutexSafeWrapper safeMutexPtr(&masterServerThreadPtrChangeAccessor);
masterServerThreadInDeletion = false;
@ -376,6 +241,20 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateMasterserver::setConsolePos(int yPos){
consoleIRC.setYPos(yPos);
lines[2].setY(consoleIRC.getYPos()-10);
chatManager.setYPos(consoleIRC.getYPos()-20);
}
void MenuStateMasterserver::setButtonLinePosition(int pos){
buttonReturn.setY(pos);
buttonCreateGame.setY(pos);
buttonRefresh.setY(pos);
labelAutoRefresh.setY(pos+30);
listBoxAutoRefresh.setY(pos);
}
void MenuStateMasterserver::IRC_CallbackEvent(const char* origin, const char **params, unsigned int count) {
//printf ("===> IRC: '%s' said in channel %s: %s\n",origin ? origin : "someone",params[0], params[1] );
char szBuf[4096]="";
@ -415,6 +294,7 @@ void MenuStateMasterserver::cleanup() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
clearServerLines();
clearUserButtons();
//printf("Exiting master server menu [%p]\n",ircClient);
if(ircClient != NULL) {
@ -437,7 +317,6 @@ MenuStateMasterserver::~MenuStateMasterserver() {
//printf("In [%s::%s Line: %d] [%p]\n",__FILE__,__FUNCTION__,__LINE__,ircClient);
cleanup();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -448,6 +327,13 @@ void MenuStateMasterserver::clearServerLines() {
}
}
void MenuStateMasterserver::clearUserButtons() {
while(!userButtons.empty()){
delete userButtons.back();
userButtons.pop_back();
}
}
void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -540,9 +426,11 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
}
else {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
for(int i=0; i<serverLines.size(); ++i){
bool clicked=false;
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
if(serverLines[i]->buttonMouseClick(x, y)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
clicked=true;
soundRenderer.playFx(coreData.getClickSoundB());
string connectServerIP = serverLines[i]->getMasterServerInfo()->getIpAddress();
int connectServerPort = serverLines[i]->getMasterServerInfo()->getExternalConnectPort();
@ -565,6 +453,23 @@ void MenuStateMasterserver::mouseClick(int x, int y, MouseButton mouseButton){
break;
}
}
if(!clicked){
for(int i = 0; i < userButtons.size(); ++i) {
if(userButtons[i]->mouseClick(x, y)) {
clicked=true;
if(!chatManager.getEditEnabled())
{
chatManager.switchOnEdit();
chatManager.addText(userButtons[i]->getText()+" ");
}
else
{
chatManager.addText(userButtons[i]->getText());
}
break;
}
}
}
}
}
@ -579,9 +484,13 @@ void MenuStateMasterserver::mouseMove(int x, int y, const MouseState *ms){
buttonCreateGame.mouseMove(x, y);
listBoxAutoRefresh.mouseMove(x, y);
for(int i=0; i<serverLines.size(); ++i){
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
serverLines[i]->buttonMouseMove(x, y);
}
for(int i = 0; i < userButtons.size(); ++i) {
userButtons[i]->mouseMove(x, y);
}
}
void MenuStateMasterserver::render(){
@ -593,18 +502,10 @@ void MenuStateMasterserver::render(){
}
else
{
renderer.renderButton(&buttonRefresh);
renderer.renderButton(&buttonReturn);
renderer.renderLabel(&labelTitle,&GREEN);
renderer.renderLabel(&announcementLabel,&YELLOW);
renderer.renderLabel(&versionInfoLabel);
renderer.renderLabel(&labelAutoRefresh);
renderer.renderLabel(&labelChatUrl);
renderer.renderButton(&buttonCreateGame);
renderer.renderListBox(&listBoxAutoRefresh);
// Render titles for server games listed
const Vec4f titleLabelColor = CYAN;
@ -636,14 +537,26 @@ void MenuStateMasterserver::render(){
renderer.renderLabel(&ircOnlinePeopleLabel,&titleLabelColor);
}
const Vec4f titleLabelColorList = YELLOW;
renderer.renderLabel(&ircOnlinePeopleListLabel,&titleLabelColorList);
for(int i=0; i<serverLines.size(); ++i){
for(int i=0; i<serverLines.size() && i<serverLinesToRender; ++i){
serverLines[i]->render();
}
for(int i=0; i<sizeof(lines) / sizeof(lines[0]); ++i){
renderer.renderLine(&lines[i]);
}
renderer.renderButton(&buttonRefresh);
renderer.renderButton(&buttonReturn);
renderer.renderLabel(&labelAutoRefresh);
renderer.renderButton(&buttonCreateGame);
renderer.renderListBox(&listBoxAutoRefresh);
for(int i = 0; i < userButtons.size(); ++i) {
renderer.renderButton(userButtons[i]);
}
renderer.renderChatManager(&chatManager);
renderer.renderConsole(&consoleIRC,false,true);
renderer.renderConsole(&consoleIRC,true,true);
}
if(program != NULL) program->renderProgramMsgBox();
}
@ -655,6 +568,10 @@ void MenuStateMasterserver::update() {
lastRefreshTimer= time(NULL);
}
// calculate button linepos:
setButtonLinePosition(serverLinesYBase-serverLinesToRender*serverLinesLineHeight);
if(playServerFoundSound)
{
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
@ -674,19 +591,34 @@ void MenuStateMasterserver::update() {
//console
consoleIRC.update();
if(ircClient != NULL) {
std::vector<string> nickList = ircClient->getNickList();
string nicks = "";
for(int i = 0; i < nickList.size(); ++i) {
if(nicks != "") {
nicks += ", ";
}
nicks += nickList[i];
bool isNew=false;
//check if there is something new
if( oldNickList.size()!=nickList.size()) {
isNew=true;
}
else {
for(int i = 0; i < nickList.size(); ++i) {
if(nickList[i]!=oldNickList[i])
{
isNew=true;
break;
}
}
}
if(isNew) {
clearUserButtons();
for(int i = 0; i < nickList.size(); ++i) {
GraphicButton *button=new GraphicButton();
button->init(userButtonsXBase,userButtonsYBase-userButtonsLineHeight*(i+1),userButtonsWidth,userButtonsHeight);
button->setFont(CoreData::getInstance().getDisplayFontSmall());
button->setText(nickList[i]);
userButtons.push_back(button);
}
oldNickList=nickList;
}
ircOnlinePeopleListLabel.setText(nicks);
}
else {
ircOnlinePeopleListLabel.setText("");
}
if(threadedErrorMsg != "") {
@ -746,17 +678,63 @@ void MenuStateMasterserver::updateServerInfo() {
if(announcementURL != "") {
std::string announcementTxt = SystemFlags::getHTTP(announcementURL);
if(StartsWith(announcementTxt,"Announcement from Masterserver:") == true) {
announcementLabel.setText(announcementTxt);
int newlineCount=0;
size_t lastIndex=0;
//announcementLabel.setText(announcementTxt);
consoleIRC.addLine(announcementTxt);
while(true){
lastIndex=announcementTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos)
{
break;
}
else
{
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ){
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
string versionURL = Config::getInstance().getString("VersionURL","http://master.megaglest.org/files/versions/")+glestVersionString+".txt";
//printf("\nversionURL=%s\n",versionURL.c_str());
if(versionURL != "") {
std::string versionTxt = SystemFlags::getHTTP(versionURL);
if(StartsWith(versionTxt,"Version info:") == true) {
versionInfoLabel.setText(versionTxt);
int newlineCount=0;
size_t lastIndex=0;
//versionInfoLabel.setText(versionTxt);
consoleIRC.addLine(versionTxt);
while(true){
lastIndex=versionTxt.find("\n",lastIndex+1);
if(lastIndex==string::npos)
{
break;
}
else
{
newlineCount++;
}
}
newlineCount--;// remove my own line
for( int i=0; i< newlineCount;++i ){
consoleIRC.addLine("");
}
}
}
consoleIRC.addLine("---------------------------------------------");
// write hint to console:
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
consoleIRC.addLine(Lang::getInstance().get("To switch off music press")+" - \""+configKeys.getCharKey("ToggleMusic")+"\"");
announcementLoaded=true;
}
@ -819,7 +797,7 @@ void MenuStateMasterserver::updateServerInfo() {
safeMutexPtr.ReleaseLock(true);
safeMutex.Lock();
serverLines.push_back(new ServerLine( masterServerInfo, i, containerName));
serverLines.push_back(new ServerLine( masterServerInfo, i, serverLinesYBase, serverLinesLineHeight, containerName));
safeMutex.ReleaseLock(true);
}
else {

View File

@ -13,6 +13,7 @@
#define _GLEST_GAME_MENUSTATEMASTERSERVER_H_
#include "main_menu.h"
#include "server_line.h"
#include "masterserver_info.h"
#include "simple_threads.h"
#include "network_interface.h"
@ -22,55 +23,11 @@
namespace Glest{ namespace Game{
// ===============================
// ServerLine
// ===============================
class ServerLine {
private:
MasterServerInfo masterServerInfo;
int index;
GraphicButton selectButton;
GraphicLabel gameFull;
//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;
GraphicLabel externalConnectPort;
const char * containerName;
std::vector<std::string> registeredObjNameList;
public:
ServerLine( MasterServerInfo *mServerInfo, int lineIndex, const char *containerName);
virtual ~ServerLine();
MasterServerInfo *getMasterServerInfo() {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<GraphicButton*> UserButtons;
typedef vector<MasterServerInfo*> MasterServerInfos;
class MenuStateMasterserver : public MenuState, public SimpleTaskCallbackInterface, public IRCCallbackInterface {
@ -83,14 +40,12 @@ private:
GraphicLabel labelAutoRefresh;
GraphicListBox listBoxAutoRefresh;
GraphicLabel labelTitle;
ServerLines serverLines;
GraphicLabel labelChatUrl;
GraphicLabel announcementLabel;
GraphicLabel versionInfoLabel;
GraphicLine lines[3];
GraphicLabel glestVersionLabel;
GraphicLabel platformLabel;
//GraphicLabel binaryCompileDateLabel;
@ -113,7 +68,6 @@ private:
int mainMessageBoxState;
GraphicLabel ircOnlinePeopleLabel;
GraphicLabel ircOnlinePeopleListLabel;
bool announcementLoaded;
bool needUpdateFromServer;
@ -121,6 +75,19 @@ private:
time_t lastRefreshTimer;
SimpleTaskThread *updateFromMasterserverThread;
bool playServerFoundSound;
ServerLines serverLines;
int serverLinesToRender;
int serverLinesYBase;
int serverLinesLineHeight;
UserButtons userButtons;
UserButtons userButtonsToRemove;
int userButtonsToRender;
int userButtonsYBase;
int userButtonsXBase;
int userButtonsLineHeight;
int userButtonsHeight;
int userButtonsWidth;
//Console console;
@ -132,6 +99,7 @@ private:
std::vector<string> ircArgs;
IRCThread *ircClient;
std::vector<string> oldNickList;
Console consoleIRC;
ChatManager chatManager;
@ -158,7 +126,10 @@ public:
private:
void showMessageBox(const string &text, const string &header, bool toggle);
bool connectToServer(string ipString, int port);
void setConsolePos(int yPos);
void setButtonLinePosition(int pos);
void clearServerLines();
void clearUserButtons();
void updateServerInfo();
void cleanup();

View File

@ -234,12 +234,10 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelFullscreenWindowed.registerGraphicComponent(containerName,"labelFullscreenWindowed");
labelFullscreenWindowed.init(leftLabelStart, leftline);
listBoxFullscreenWindowed.registerGraphicComponent(containerName,"listBoxFullscreenWindowed");
listBoxFullscreenWindowed.init(leftColumnStart, leftline, 80);
checkBoxFullscreenWindowed.registerGraphicComponent(containerName,"checkBoxFullscreenWindowed");
checkBoxFullscreenWindowed.init(leftColumnStart, leftline);
labelFullscreenWindowed.setText(lang.get("Windowed"));
listBoxFullscreenWindowed.pushBackItem(lang.get("No"));
listBoxFullscreenWindowed.pushBackItem(lang.get("Yes"));
listBoxFullscreenWindowed.setSelectedItemIndex(clamp(config.getBool("Windowed"), false, true));
checkBoxFullscreenWindowed.setValue(config.getBool("Windowed"));
leftline-=30;
//filter
@ -272,12 +270,10 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelTextures3D.registerGraphicComponent(containerName,"labelTextures3D");
labelTextures3D.init(leftLabelStart, leftline);
listBoxTextures3D.registerGraphicComponent(containerName,"listBoxTextures3D");
listBoxTextures3D.init(leftColumnStart, leftline, 80);
checkBoxTextures3D.registerGraphicComponent(containerName,"checkBoxTextures3D");
checkBoxTextures3D.init(leftColumnStart, leftline);
labelTextures3D.setText(lang.get("Textures3D"));
listBoxTextures3D.pushBackItem(lang.get("No"));
listBoxTextures3D.pushBackItem(lang.get("Yes"));
listBoxTextures3D.setSelectedItemIndex(clamp(config.getBool("Textures3D"), false, true));
checkBoxTextures3D.setValue(config.getBool("Textures3D"));
leftline-=30;
//lights
@ -298,11 +294,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelUnitParticles.init(leftLabelStart,leftline);
labelUnitParticles.setText(lang.get("ShowUnitParticles"));
listBoxUnitParticles.registerGraphicComponent(containerName,"listBoxUnitParticles");
listBoxUnitParticles.init(leftColumnStart,leftline,80);
listBoxUnitParticles.pushBackItem(lang.get("No"));
listBoxUnitParticles.pushBackItem(lang.get("Yes"));
listBoxUnitParticles.setSelectedItemIndex(clamp(config.getBool("UnitParticles"), 0, 1));
checkBoxUnitParticles.registerGraphicComponent(containerName,"checkBoxUnitParticles");
checkBoxUnitParticles.init(leftColumnStart,leftline);
checkBoxUnitParticles.setValue(config.getBool("UnitParticles"));
leftline-=30;
//unit particles
@ -310,11 +304,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
labelMapPreview.init(leftLabelStart,leftline);
labelMapPreview.setText(lang.get("ShowMapPreview"));
listBoxMapPreview.registerGraphicComponent(containerName,"listBoxMapPreview");
listBoxMapPreview.init(leftColumnStart,leftline,80);
listBoxMapPreview.pushBackItem(lang.get("No"));
listBoxMapPreview.pushBackItem(lang.get("Yes"));
listBoxMapPreview.setSelectedItemIndex(clamp(config.getBool("MapPreview","true"), 0, 1));
checkBoxMapPreview.registerGraphicComponent(containerName,"checkBoxMapPreview");
checkBoxMapPreview.init(leftColumnStart,leftline);
checkBoxMapPreview.setValue(config.getBool("MapPreview","true"));
leftline-=30;
// buttons
@ -403,7 +395,7 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
}
bool currentFullscreenWindowed=config.getBool("Windowed");
bool selectedFullscreenWindowed = (listBoxFullscreenWindowed.getSelectedItemIndex() != 0);
bool selectedFullscreenWindowed = checkBoxFullscreenWindowed.getValue();
if(currentFullscreenWindowed!=selectedFullscreenWindowed){
mainMessageBoxState=1;
Lang &lang= Lang::getInstance();
@ -441,9 +433,9 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
listBoxLang.mouseClick(x, y);
listBoxShadows.mouseClick(x, y);
listBoxFilter.mouseClick(x, y);
listBoxTextures3D.mouseClick(x, y);
listBoxUnitParticles.mouseClick(x, y);
listBoxMapPreview.mouseClick(x, y);
checkBoxTextures3D.mouseClick(x, y);
checkBoxUnitParticles.mouseClick(x, y);
checkBoxMapPreview.mouseClick(x, y);
listBoxLights.mouseClick(x, y);
listBoxSoundFactory.mouseClick(x, y);
listBoxVolumeFx.mouseClick(x, y);
@ -451,7 +443,7 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
listBoxVolumeMusic.mouseClick(x, y);
listBoxScreenModes.mouseClick(x, y);
listFontSizeAdjustment.mouseClick(x, y);
listBoxFullscreenWindowed.mouseClick(x, y);
checkBoxFullscreenWindowed.mouseClick(x, y);
listBoxPublishServerExternalPort.mouseClick(x, y);
}
}
@ -473,11 +465,12 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){
listBoxLang.mouseMove(x, y);
listBoxFilter.mouseMove(x, y);
listBoxShadows.mouseMove(x, y);
listBoxTextures3D.mouseMove(x, y);
listBoxUnitParticles.mouseMove(x, y);
listBoxMapPreview.mouseMove(x, y);
checkBoxTextures3D.mouseMove(x, y);
checkBoxUnitParticles.mouseMove(x, y);
checkBoxMapPreview.mouseMove(x, y);
listBoxLights.mouseMove(x, y);
listBoxScreenModes.mouseMove(x, y);
checkBoxFullscreenWindowed.mouseMove(x, y);
listFontSizeAdjustment.mouseMove(x, y);
listBoxPublishServerExternalPort.mouseMove(x, y);
}
@ -540,9 +533,9 @@ void MenuStateOptions::render(){
renderer.renderButton(&buttonKeyboardSetup);
renderer.renderListBox(&listBoxLang);
renderer.renderListBox(&listBoxShadows);
renderer.renderListBox(&listBoxTextures3D);
renderer.renderListBox(&listBoxUnitParticles);
renderer.renderListBox(&listBoxMapPreview);
renderer.renderCheckBox(&checkBoxTextures3D);
renderer.renderCheckBox(&checkBoxUnitParticles);
renderer.renderCheckBox(&checkBoxMapPreview);
renderer.renderListBox(&listBoxLights);
renderer.renderListBox(&listBoxFilter);
renderer.renderListBox(&listBoxSoundFactory);
@ -572,7 +565,7 @@ void MenuStateOptions::render(){
renderer.renderListBox(&listFontSizeAdjustment);
renderer.renderLabel(&labelFontSizeAdjustment);
renderer.renderLabel(&labelFullscreenWindowed);
renderer.renderListBox(&listBoxFullscreenWindowed);
renderer.renderCheckBox(&checkBoxFullscreenWindowed);
renderer.renderLabel(&labelPublishServerExternalPort);
renderer.renderListBox(&listBoxPublishServerExternalPort);
}
@ -596,11 +589,11 @@ void MenuStateOptions::saveConfig(){
int index= listBoxShadows.getSelectedItemIndex();
config.setString("Shadows", Renderer::shadowsToStr(static_cast<Renderer::Shadows>(index)));
config.setBool("Windowed", (listBoxFullscreenWindowed.getSelectedItemIndex() != 0));
config.setBool("Windowed", checkBoxFullscreenWindowed.getValue());
config.setString("Filter", listBoxFilter.getSelectedItem());
config.setBool("Textures3D", (listBoxTextures3D.getSelectedItemIndex() != 0));
config.setBool("UnitParticles", (listBoxUnitParticles.getSelectedItemIndex() != 0));
config.setBool("MapPreview", (listBoxMapPreview.getSelectedItemIndex() != 0));
config.setBool("Textures3D", checkBoxTextures3D.getValue());
config.setBool("UnitParticles", (checkBoxUnitParticles.getValue()));
config.setBool("MapPreview", checkBoxMapPreview.getValue());
config.setInt("MaxLights", listBoxLights.getSelectedItemIndex()+1);
config.setString("FactorySound", listBoxSoundFactory.getSelectedItem());
config.setString("SoundVolumeFx", listBoxVolumeFx.getSelectedItem());

View File

@ -43,9 +43,9 @@ private:
GraphicListBox listBoxLang;
GraphicListBox listBoxShadows;
GraphicListBox listBoxFilter;
GraphicListBox listBoxTextures3D;
GraphicCheckBox checkBoxTextures3D;
GraphicListBox listBoxLights;
GraphicListBox listBoxUnitParticles;
GraphicCheckBox checkBoxUnitParticles;
GraphicListBox listBoxSoundFactory;
GraphicListBox listBoxVolumeFx;
GraphicListBox listBoxVolumeAmbient;
@ -62,7 +62,7 @@ private:
list<ModeInfo> modeInfos;
GraphicLabel labelFullscreenWindowed;
GraphicListBox listBoxFullscreenWindowed;
GraphicCheckBox checkBoxFullscreenWindowed;
GraphicLabel labelVideoSection;
GraphicLabel labelAudioSection;
@ -72,7 +72,7 @@ private:
GraphicListBox listFontSizeAdjustment;
GraphicLabel labelMapPreview;
GraphicListBox listBoxMapPreview;
GraphicCheckBox checkBoxMapPreview;
GraphicMessageBox mainMessageBox;
int mainMessageBoxState;

View File

@ -0,0 +1,180 @@
// ==============================================================
// 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 "server_line.h"
#include "renderer.h"
#include "core_data.h"
#include "config.h"
#include "metrics.h"
#include "auto_test.h"
#include "masterserver_info.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
// =====================================================
// class ServerLine
// =====================================================
ServerLine::ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, int lineHeight, const char * containerName) {
this->containerName = containerName;
Lang &lang= Lang::getInstance();
index=lineIndex;
this->lineHeight=lineHeight;
int lineOffset = lineHeight * lineIndex;
masterServerInfo = *mServerInfo;
int i=10;
this->baseY=baseY;
//general info:
i+=10;
glestVersionLabel.registerGraphicComponent(containerName,"glestVersionLabel" + intToStr(lineIndex));
registeredObjNameList.push_back("glestVersionLabel" + intToStr(lineIndex));
glestVersionLabel.init(i,baseY-lineOffset);
glestVersionLabel.setText(masterServerInfo.getGlestVersion());
i+=80;
registeredObjNameList.push_back("platformLabel" + intToStr(lineIndex));
platformLabel.registerGraphicComponent(containerName,"platformLabel" + intToStr(lineIndex));
platformLabel.init(i,baseY-lineOffset);
platformLabel.setText(masterServerInfo.getPlatform());
// i+=50;
// registeredObjNameList.push_back("binaryCompileDateLabel" + intToStr(lineIndex));
// binaryCompileDateLabel.registerGraphicComponent(containerName,"binaryCompileDateLabel" + intToStr(lineIndex));
// binaryCompileDateLabel.init(i,baseY-lineOffset);
// binaryCompileDateLabel.setText(masterServerInfo.getBinaryCompileDate());
//game info:
i+=130;
registeredObjNameList.push_back("serverTitleLabel" + intToStr(lineIndex));
serverTitleLabel.registerGraphicComponent(containerName,"serverTitleLabel" + intToStr(lineIndex));
serverTitleLabel.init(i,baseY-lineOffset);
serverTitleLabel.setText(masterServerInfo.getServerTitle());
i+=210;
registeredObjNameList.push_back("ipAddressLabel" + intToStr(lineIndex));
ipAddressLabel.registerGraphicComponent(containerName,"ipAddressLabel" + intToStr(lineIndex));
ipAddressLabel.init(i,baseY-lineOffset);
ipAddressLabel.setText(masterServerInfo.getIpAddress());
//game setup info:
i+=100;
registeredObjNameList.push_back("techLabel" + intToStr(lineIndex));
techLabel.registerGraphicComponent(containerName,"techLabel" + intToStr(lineIndex));
techLabel.init(i,baseY-lineOffset);
techLabel.setText(masterServerInfo.getTech());
i+=100;
registeredObjNameList.push_back("mapLabel" + intToStr(lineIndex));
mapLabel.registerGraphicComponent(containerName,"mapLabel" + intToStr(lineIndex));
mapLabel.init(i,baseY-lineOffset);
mapLabel.setText(masterServerInfo.getMap());
i+=100;
registeredObjNameList.push_back("tilesetLabel" + intToStr(lineIndex));
tilesetLabel.registerGraphicComponent(containerName,"tilesetLabel" + intToStr(lineIndex));
tilesetLabel.init(i,baseY-lineOffset);
tilesetLabel.setText(masterServerInfo.getTileset());
i+=100;
registeredObjNameList.push_back("activeSlotsLabel" + intToStr(lineIndex));
activeSlotsLabel.registerGraphicComponent(containerName,"activeSlotsLabel" + intToStr(lineIndex));
activeSlotsLabel.init(i,baseY-lineOffset);
activeSlotsLabel.setText(intToStr(masterServerInfo.getActiveSlots())+"/"+intToStr(masterServerInfo.getNetworkSlots())+"/"+intToStr(masterServerInfo.getConnectedClients()));
i+=50;
registeredObjNameList.push_back("externalConnectPort" + intToStr(lineIndex));
externalConnectPort.registerGraphicComponent(containerName,"externalConnectPort" + intToStr(lineIndex));
externalConnectPort.init(i,baseY-lineOffset);
externalConnectPort.setText(intToStr(masterServerInfo.getExternalConnectPort()));
i+=50;
registeredObjNameList.push_back("selectButton" + intToStr(lineIndex));
selectButton.registerGraphicComponent(containerName,"selectButton" + intToStr(lineIndex));
selectButton.init(i, baseY-lineOffset, 30);
selectButton.setText(">");
//printf("glestVersionString [%s] masterServerInfo->getGlestVersion() [%s]\n",glestVersionString.c_str(),masterServerInfo->getGlestVersion().c_str());
bool compatible = checkVersionComptability(glestVersionString, masterServerInfo.getGlestVersion());
selectButton.setEnabled(compatible);
selectButton.setEditable(compatible);
registeredObjNameList.push_back("gameFull" + intToStr(lineIndex));
gameFull.registerGraphicComponent(containerName,"gameFull" + intToStr(lineIndex));
gameFull.init(i, baseY-lineOffset);
gameFull.setText(lang.get("MGGameSlotsFull"));
gameFull.setEnabled(!compatible);
gameFull.setEditable(!compatible);
GraphicComponent::applyAllCustomProperties(containerName);
}
ServerLine::~ServerLine() {
GraphicComponent::clearRegisterGraphicComponent(containerName, registeredObjNameList);
//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();
bool joinEnabled = (masterServerInfo.getNetworkSlots() > masterServerInfo.getConnectedClients());
if(joinEnabled == true) {
selectButton.setEnabled(true);
selectButton.setVisible(true);
gameFull.setEnabled(false);
gameFull.setEditable(false);
renderer.renderButton(&selectButton);
}
else {
selectButton.setEnabled(false);
selectButton.setVisible(false);
gameFull.setEnabled(true);
gameFull.setEditable(true);
renderer.renderLabel(&gameFull);
}
//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);
renderer.renderLabel(&externalConnectPort);
}
}}//end namespace

View File

@ -0,0 +1,73 @@
// ==============================================================
// 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
// ==============================================================
#ifndef _GLEST_GAME_SERVERLINE_H_
#define _GLEST_GAME_SERVERLINE_H_
#include "masterserver_info.h"
#include "components.h"
#include "lang.h"
#include "world.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
// ===============================
// ServerLine
// ===============================
class ServerLine {
private:
MasterServerInfo masterServerInfo;
int index;
int lineHeight;
int baseY;
GraphicButton selectButton;
GraphicLabel gameFull;
//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;
GraphicLabel externalConnectPort;
const char * containerName;
std::vector<std::string> registeredObjNameList;
public:
ServerLine( MasterServerInfo *mServerInfo, int lineIndex, int baseY, int lineHeight, const char *containerName);
virtual ~ServerLine();
MasterServerInfo *getMasterServerInfo() {return &masterServerInfo;}
const int getIndex() const {return index;}
const int getLineHeight() const {return lineHeight;}
bool buttonMouseClick(int x, int y);
bool buttonMouseMove(int x, int y);
//void setIndex(int value);
void render();
};
}}//end namespace
#endif