From b52ca803882a16ef3f8fab414c608704effa9eea Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 5 Nov 2010 23:12:46 +0000 Subject: [PATCH] - to make ultifd happy, fixed overlapping labels in lobbies --- .../menu/menu_state_connected_game.cpp | 26 +++++++++++++++++++ .../menu/menu_state_custom_game.cpp | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 84ad6ce27..d81b86976 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -543,6 +543,28 @@ void MenuStateConnectedGame::render() { // Get a reference to the player texture cache std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); + // START - this code ensure player title and player names don't overlap + int offsetPosition=0; + for(int i=0; i < GameConstants::maxPlayers; ++i) { + //labelPlayers[i].registerGraphicComponent(containerName,"labelPlayers" + intToStr(i)); + //labelPlayers[i].init(xoffset+50, setupPos-30-i*rowHeight); + + const Metrics &metrics= Metrics::getInstance(); + const FontMetrics *fontMetrics= CoreData::getInstance().getMenuFontNormal()->getMetrics(); + if(fontMetrics == NULL) { + throw runtime_error("fontMetrics == NULL"); + } + int curWidth = (metrics.toVirtualX(fontMetrics->getTextWidth(labelPlayers[i].getText()))); + + if(labelPlayers[i].getX() + curWidth >= labelPlayerNames[i].getX()) { + int newOffsetPosition = labelPlayers[i].getX() + curWidth + 2; + if(offsetPosition < newOffsetPosition) { + offsetPosition = newOffsetPosition; + } + } + } + // END + for(int i = 0; i < GameConstants::maxPlayers; ++i) { if(crcPlayerTextureCache[i] != NULL) { // Render the player # label the player's color @@ -560,6 +582,10 @@ void MenuStateConnectedGame::render() { renderer.renderLabel(&labelPlayers[i]); } + if(offsetPosition > 0) { + labelPlayerNames[i].setX(offsetPosition); + } + renderer.renderListBox(&listBoxControls[i]); if(listBoxControls[i].getSelectedItemIndex()!=ctClosed){ renderer.renderListBox(&listBoxFactions[i]); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 874208065..7b7c780cf 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -347,6 +347,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b //listBoxEnableServerControlledAI.pushBackItem(lang.get("No")); //listBoxEnableServerControlledAI.setSelectedItemIndex(0); + //list boxes xoffset=120; int rowHeight=27; @@ -1140,6 +1141,28 @@ void MenuStateCustomGame::render() { // Get a reference to the player texture cache std::map &crcPlayerTextureCache = CacheManager::getCachedItem< std::map >(GameConstants::playerTextureCacheLookupKey); + // START - this code ensure player title and player names don't overlap + int offsetPosition=0; + for(int i=0; i < GameConstants::maxPlayers; ++i) { + //labelPlayers[i].registerGraphicComponent(containerName,"labelPlayers" + intToStr(i)); + //labelPlayers[i].init(xoffset+50, setupPos-30-i*rowHeight); + + const Metrics &metrics= Metrics::getInstance(); + const FontMetrics *fontMetrics= CoreData::getInstance().getMenuFontNormal()->getMetrics(); + if(fontMetrics == NULL) { + throw runtime_error("fontMetrics == NULL"); + } + int curWidth = (metrics.toVirtualX(fontMetrics->getTextWidth(labelPlayers[i].getText()))); + + if(labelPlayers[i].getX() + curWidth >= labelPlayerNames[i].getX()) { + int newOffsetPosition = labelPlayers[i].getX() + curWidth + 2; + if(offsetPosition < newOffsetPosition) { + offsetPosition = newOffsetPosition; + } + } + } + // END + for(int i = 0; i < GameConstants::maxPlayers; ++i) { if(crcPlayerTextureCache[i] != NULL) { // Render the player # label the player's color @@ -1157,6 +1180,9 @@ void MenuStateCustomGame::render() { renderer.renderLabel(&labelPlayers[i]); } + if(offsetPosition > 0) { + labelPlayerNames[i].setX(offsetPosition); + } renderer.renderLabel(&labelPlayerNames[i]); renderer.renderListBox(&listBoxControls[i]);