- updated network menus to hide player rows that are not applicable to the map selected
- added new visible property to graphical controls
This commit is contained in:
parent
0c99a516c5
commit
350d658ceb
|
@ -42,8 +42,9 @@ GraphicComponent::GraphicComponent(std::string containerName, std::string objNam
|
|||
if(objName != "") {
|
||||
registerGraphicComponent(containerName,objName);
|
||||
}
|
||||
enabled= true;
|
||||
editable= true;
|
||||
enabled = true;
|
||||
editable = true;
|
||||
visible = true;
|
||||
}
|
||||
|
||||
void GraphicComponent::clearRegisteredComponents(std::string containerName) {
|
||||
|
@ -190,7 +191,11 @@ void GraphicComponent::init(int x, int y, int w, int h) {
|
|||
enabled= true;
|
||||
}
|
||||
|
||||
bool GraphicComponent::mouseMove(int x, int y){
|
||||
bool GraphicComponent::mouseMove(int x, int y) {
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
x > this->x &&
|
||||
y > this->y &&
|
||||
|
@ -199,7 +204,7 @@ bool GraphicComponent::mouseMove(int x, int y){
|
|||
}
|
||||
|
||||
bool GraphicComponent::mouseClick(int x, int y){
|
||||
if(getEnabled()&&getEditable())
|
||||
if(getVisible() && getEnabled() && getEditable())
|
||||
return mouseMove(x, y);
|
||||
else
|
||||
return false;
|
||||
|
@ -241,7 +246,11 @@ void GraphicButton::init(int x, int y, int w, int h){
|
|||
}
|
||||
|
||||
bool GraphicButton::mouseMove(int x, int y){
|
||||
bool b= GraphicComponent::mouseMove(x, y);
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b= GraphicComponent::mouseMove(x, y);
|
||||
lighted= b;
|
||||
return b;
|
||||
}
|
||||
|
@ -306,12 +315,20 @@ void GraphicListBox::setSelectedItem(string item, bool errorOnMissing){
|
|||
}
|
||||
|
||||
bool GraphicListBox::mouseMove(int x, int y){
|
||||
return
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
graphButton1.mouseMove(x, y) ||
|
||||
graphButton2.mouseMove(x, y);
|
||||
}
|
||||
|
||||
bool GraphicListBox::mouseClick(int x, int y){
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!items.empty()){
|
||||
bool b1= graphButton1.mouseClick(x, y);
|
||||
bool b2= graphButton2.mouseClick(x, y);
|
||||
|
@ -369,11 +386,19 @@ void GraphicMessageBox::init(const string &button1Str){
|
|||
}
|
||||
|
||||
bool GraphicMessageBox::mouseMove(int x, int y){
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return button1.mouseMove(x, y) || button2.mouseMove(x, y);
|
||||
}
|
||||
|
||||
bool GraphicMessageBox::mouseClick(int x, int y){
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
bool b2= button2.mouseClick(x, y);
|
||||
if(buttonCount==1){
|
||||
return b1;
|
||||
|
@ -384,7 +409,11 @@ bool GraphicMessageBox::mouseClick(int x, int y){
|
|||
}
|
||||
|
||||
bool GraphicMessageBox::mouseClick(int x, int y, int &clickedButton){
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
if(this->getVisible() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b1= button1.mouseClick(x, y);
|
||||
bool b2= button2.mouseClick(x, y);
|
||||
|
||||
if(buttonCount==1){
|
||||
|
|
|
@ -47,6 +47,7 @@ protected:
|
|||
const Font2D *font;
|
||||
bool enabled;
|
||||
bool editable;
|
||||
bool visible;
|
||||
|
||||
static float anim;
|
||||
static float fade;
|
||||
|
@ -75,7 +76,8 @@ public:
|
|||
const string &getText() const {return text;}
|
||||
const Font2D *getFont() const {return font;}
|
||||
bool getEnabled() const {return enabled;}
|
||||
bool getEditable() const {return editable;}
|
||||
bool getEditable() const {return editable;}
|
||||
bool getVisible() const {return visible;}
|
||||
|
||||
void setX(int x) {this->x= x;}
|
||||
void setY(int y) {this->y= y;}
|
||||
|
@ -83,6 +85,7 @@ public:
|
|||
void setFont(const Font2D *font) {this->font= font;}
|
||||
void setEnabled(bool enabled) {this->enabled= enabled;}
|
||||
void setEditable(bool editable) {this->editable= editable;}
|
||||
void setVisible(bool value) {this->visible = value;}
|
||||
|
||||
virtual bool mouseMove(int x, int y);
|
||||
virtual bool mouseClick(int x, int y);
|
||||
|
|
|
@ -1027,7 +1027,10 @@ void Renderer::renderTextShadow(const string &text, const Font2D *font,const Vec
|
|||
|
||||
// ============= COMPONENTS =============================
|
||||
|
||||
void Renderer::renderLabel(const GraphicLabel *label){
|
||||
void Renderer::renderLabel(const GraphicLabel *label) {
|
||||
if(label->getVisible() == false) {
|
||||
return;
|
||||
}
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
@ -1049,7 +1052,11 @@ void Renderer::renderLabel(const GraphicLabel *label){
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
void Renderer::renderButton(const GraphicButton *button){
|
||||
void Renderer::renderButton(const GraphicButton *button) {
|
||||
if(button->getVisible() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x= button->getX();
|
||||
int y= button->getY();
|
||||
int h= button->getH();
|
||||
|
@ -1152,7 +1159,10 @@ void Renderer::renderButton(const GraphicButton *button){
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
void Renderer::renderListBox(const GraphicListBox *listBox){
|
||||
void Renderer::renderListBox(const GraphicListBox *listBox) {
|
||||
if(listBox->getVisible() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
renderButton(listBox->getButton1());
|
||||
renderButton(listBox->getButton2());
|
||||
|
@ -1169,7 +1179,10 @@ void Renderer::renderListBox(const GraphicListBox *listBox){
|
|||
glPopAttrib();
|
||||
}
|
||||
|
||||
void Renderer::renderMessageBox(const GraphicMessageBox *messageBox){
|
||||
void Renderer::renderMessageBox(const GraphicMessageBox *messageBox) {
|
||||
if(messageBox->getVisible() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
//background
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||
|
|
|
@ -74,13 +74,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
defaultPlayerName = config.getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
enableFactionTexturePreview = config.getBool("FactionPreview","false");
|
||||
|
||||
labelMapInfo.setText("?");
|
||||
|
||||
vector<string> teamItems, controlItems, results;
|
||||
int setupPos=590;
|
||||
int mapHeadPos=330;
|
||||
int mapPos=mapHeadPos-30;
|
||||
int aHeadPos=260;
|
||||
int aHeadPos=245;
|
||||
int aPos=aHeadPos-30;
|
||||
int networkHeadPos=700;
|
||||
int networkPos=networkHeadPos-30;
|
||||
|
@ -196,6 +194,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
listBoxEnableServerControlledAI.setEditable(false);
|
||||
|
||||
xoffset=70;
|
||||
int labelOffset=23;
|
||||
//map listBox
|
||||
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
|
||||
// will also ensure they are alphabetically listed (rather than how the OS provides them)
|
||||
|
@ -203,6 +202,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
listBoxMap.init(xoffset+100, mapPos, 200);
|
||||
listBoxMap.setEditable(false);
|
||||
|
||||
labelMapInfo.registerGraphicComponent(containerName,"labelMapInfo");
|
||||
labelMapInfo.init(xoffset+100, mapPos-labelOffset, 200, 40);
|
||||
labelMapInfo.setText("?");
|
||||
|
||||
labelMap.registerGraphicComponent(containerName,"labelMap");
|
||||
labelMap.init(xoffset+100, mapHeadPos);
|
||||
labelMap.setText(lang.get("Map"));
|
||||
|
@ -313,7 +316,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
|
|||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
labelMapInfo.setText(mapInfo.desc);
|
||||
|
||||
//loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo);
|
||||
//loadMapInfo(Map::getMapPath(""), &mapInfo);
|
||||
//labelMapInfo.setText(mapInfo.desc);
|
||||
|
||||
//init controllers
|
||||
listBoxControls[0].setSelectedItemIndex(ctHuman);
|
||||
|
@ -531,7 +537,7 @@ void MenuStateConnectedGame::render() {
|
|||
renderer.renderLabel(&labelControl);
|
||||
renderer.renderLabel(&labelFaction);
|
||||
renderer.renderLabel(&labelTeam);
|
||||
//renderer.renderLabel(&labelMapInfo);
|
||||
renderer.renderLabel(&labelMapInfo);
|
||||
|
||||
renderer.renderListBox(&listBoxMap);
|
||||
renderer.renderListBox(&listBoxFogOfWar);
|
||||
|
@ -689,19 +695,15 @@ void MenuStateConnectedGame::update() {
|
|||
}
|
||||
|
||||
if(clientInterface->getAllowGameDataSynchCheck() == true &&
|
||||
clientInterface->getNetworkGameDataSynchCheckOk() == false)
|
||||
{
|
||||
clientInterface->getNetworkGameDataSynchCheckOk() == false) {
|
||||
label = label + " -waiting to synch:";
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false)
|
||||
{
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkMap() == false) {
|
||||
label = label + " map";
|
||||
}
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false)
|
||||
{
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkTile() == false) {
|
||||
label = label + " tile";
|
||||
}
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false)
|
||||
{
|
||||
if(clientInterface->getNetworkGameDataSynchCheckOkTech() == false) {
|
||||
label = label + " techtree";
|
||||
}
|
||||
//if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false)
|
||||
|
@ -789,10 +791,11 @@ void MenuStateConnectedGame::update() {
|
|||
// map
|
||||
maps.push_back(formatString(gameSettings->getMap()));
|
||||
listBoxMap.setItems(maps);
|
||||
if(currentMap != gameSettings->getMap())
|
||||
{// load the setup again
|
||||
if(currentMap != gameSettings->getMap()) {// load the setup again
|
||||
currentMap = gameSettings->getMap();
|
||||
}
|
||||
loadMapInfo(Map::getMapPath(currentMap), &mapInfo);
|
||||
labelMapInfo.setText(mapInfo.desc);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -1246,4 +1249,51 @@ void MenuStateConnectedGame::cleanupFactionTexture() {
|
|||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
void MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo) {
|
||||
|
||||
struct MapFileHeader{
|
||||
int32 version;
|
||||
int32 maxPlayers;
|
||||
int32 width;
|
||||
int32 height;
|
||||
int32 altFactor;
|
||||
int32 waterLevel;
|
||||
int8 title[128];
|
||||
};
|
||||
|
||||
Lang &lang= Lang::getInstance();
|
||||
|
||||
try{
|
||||
FILE *f= fopen(file.c_str(), "rb");
|
||||
if(f==NULL)
|
||||
throw runtime_error("Can't open file");
|
||||
|
||||
MapFileHeader header;
|
||||
size_t readBytes = fread(&header, sizeof(MapFileHeader), 1, f);
|
||||
|
||||
mapInfo->size.x= header.width;
|
||||
mapInfo->size.y= header.height;
|
||||
mapInfo->players= header.maxPlayers;
|
||||
|
||||
mapInfo->desc= lang.get("MaxPlayers")+": "+intToStr(mapInfo->players)+"\n";
|
||||
mapInfo->desc+=lang.get("Size")+": "+intToStr(mapInfo->size.x) + " x " + intToStr(mapInfo->size.y);
|
||||
|
||||
fclose(f);
|
||||
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
labelPlayers[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxControls[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxFactions[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxTeams[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelNetStatus[i].setVisible(i+1 <= mapInfo->players);
|
||||
}
|
||||
|
||||
}
|
||||
catch(exception e){
|
||||
throw runtime_error("Error loading map file: "+file+'\n'+e.what());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -142,6 +142,7 @@ private:
|
|||
|
||||
void cleanupFactionTexture();
|
||||
void loadFactionTexture(string filepath);
|
||||
void loadMapInfo(string file, MapInfo *mapInfo);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1998,6 +1998,16 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo){
|
|||
mapInfo->desc+=lang.get("Size")+": "+intToStr(mapInfo->size.x) + " x " + intToStr(mapInfo->size.y);
|
||||
|
||||
fclose(f);
|
||||
|
||||
for(int i = 0; i < GameConstants::maxPlayers; ++i) {
|
||||
labelPlayers[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelPlayerNames[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxControls[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxFactions[i].setVisible(i+1 <= mapInfo->players);
|
||||
listBoxTeams[i].setVisible(i+1 <= mapInfo->players);
|
||||
labelNetStatus[i].setVisible(i+1 <= mapInfo->players);
|
||||
}
|
||||
|
||||
}
|
||||
catch(exception e){
|
||||
throw runtime_error("Error loading map file: "+file+'\n'+e.what());
|
||||
|
|
Loading…
Reference in New Issue
Block a user