From cf5b085b2ec357596542942d39bde6038cefb643 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 8 Sep 2010 22:37:24 +0000 Subject: [PATCH] - added ability to override UI placement for connected and custom menus --- source/glest_game/facilities/components.cpp | 58 ++++++++++++++- source/glest_game/facilities/components.h | 26 +++++-- .../menu/menu_state_connected_game.cpp | 57 +++++++++++++++ .../menu/menu_state_connected_game.h | 3 +- .../menu/menu_state_custom_game.cpp | 73 ++++++++++++++++++- .../glest_game/menu/menu_state_custom_game.h | 3 + 6 files changed, 210 insertions(+), 10 deletions(-) diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 74cf0a2d..2c2e79af 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -18,6 +18,7 @@ #include "core_data.h" #include "platform_util.h" #include "util.h" +#include "conversion.h" #include "leak_dumper.h" using namespace std; @@ -34,11 +35,66 @@ float GraphicComponent::fade= 0.f; const float GraphicComponent::animSpeed= 0.02f; const float GraphicComponent::fadeSpeed= 0.01f; -GraphicComponent::GraphicComponent(){ +std::map > GraphicComponent::registeredGraphicComponentList; + +GraphicComponent::GraphicComponent(std::string containerName, std::string objName) { + instanceName = ""; + if(objName != "") { + registerGraphicComponent(containerName,objName); + } enabled= true; editable= true; } +void GraphicComponent::registerGraphicComponent(std::string containerName, std::string objName) { + instanceName = objName; + registeredGraphicComponentList[containerName][objName] = this; +} + +GraphicComponent * GraphicComponent::findRegisteredComponent(std::string containerName, std::string objName) { + GraphicComponent *result = NULL; + + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + std::map::iterator iterFind2 = iterFind1->second.find(objName); + if(iterFind2 != iterFind1->second.end()) { + result = iterFind2->second; + } + } + return result; +} + +void GraphicComponent::applyAllCustomProperties(std::string containerName) { + + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + for(std::map::iterator iterFind2 = iterFind1->second.begin(); + iterFind2 != iterFind1->second.end(); iterFind2++) { + iterFind2->second->applyCustomProperties(containerName); + } + } +} + +void GraphicComponent::applyCustomProperties(std::string containerName) { + if(instanceName != "") { + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + std::map::iterator iterFind2 = iterFind1->second.find(instanceName); + if(iterFind2 != iterFind1->second.end()) { + Config &config = Config::getInstance(); + + //if(dynamic_cast(iterFind2->second) != NULL) { + GraphicComponent *ctl = dynamic_cast(iterFind2->second); + ctl->x = config.getInt(containerName + "_" + iterFind2->first + "_x",intToStr(ctl->x).c_str()); + ctl->y = config.getInt(containerName + "_" + iterFind2->first + "_y",intToStr(ctl->y).c_str()); + ctl->w = config.getInt(containerName + "_" + iterFind2->first + "_w",intToStr(ctl->w).c_str()); + ctl->h = config.getInt(containerName + "_" + iterFind2->first + "_h",intToStr(ctl->h).c_str()); + //} + } + } + } +} + void GraphicComponent::init(int x, int y, int w, int h){ this->x= x; this->y= y; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index 296edbca..584463f0 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -14,7 +14,8 @@ #include #include - +#include +#include #include "font.h" #include "leak_dumper.h" @@ -25,17 +26,21 @@ using Shared::Graphics::Font2D; namespace Glest{ namespace Game{ +class GraphicComponent; + // =========================================================== // class GraphicComponent // // OpenGL renderer GUI components // =========================================================== -class GraphicComponent{ +class GraphicComponent { public: static const float animSpeed; static const float fadeSpeed; + static std::map > registeredGraphicComponentList; + protected: int x, y, w, h; string text; @@ -46,10 +51,17 @@ protected: static float anim; static float fade; + string instanceName; + public: - GraphicComponent(); + GraphicComponent(std::string containerName="", std::string objName=""); virtual ~GraphicComponent(){} + void registerGraphicComponent(std::string containerName, std::string objName); + static GraphicComponent * findRegisteredComponent(std::string containerName, std::string objName); + static void applyAllCustomProperties(std::string containerName); + void applyCustomProperties(std::string containerName); + void init(int x, int y, int w, int h); int getX() const {return x;} @@ -81,7 +93,7 @@ public: // class GraphicLabel // =========================================================== -class GraphicLabel: public GraphicComponent{ +class GraphicLabel: public GraphicComponent { public: static const int defH; static const int defW; @@ -101,7 +113,7 @@ public: // class GraphicButton // =========================================================== -class GraphicButton: public GraphicComponent{ +class GraphicButton: public GraphicComponent { public: static const int defH; static const int defW; @@ -122,7 +134,7 @@ public: // class GraphicListBox // =========================================================== -class GraphicListBox: public GraphicComponent{ +class GraphicListBox: public GraphicComponent { public: static const int defH; static const int defW; @@ -155,7 +167,7 @@ public: // class GraphicMessageBox // =========================================================== -class GraphicMessageBox: public GraphicComponent{ +class GraphicMessageBox: public GraphicComponent { public: static const int defH; static const int defW; diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index b25b4338..f4eb1693 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -45,6 +45,8 @@ struct FormatString { // class MenuStateConnectedGame // ===================================================== +const char *MenuStateConnectedGame::containerName = "ClientConnectedGame"; + MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainMenu,JoinMenu joinMenuInfo, bool openNetworkSlots): MenuState(program, mainMenu, "connected-game") //← set on connected-game { @@ -86,23 +88,32 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM int xoffset=0; //state + labelStatus.registerGraphicComponent(containerName,"labelStatus"); labelStatus.init(350, networkHeadPos+30); labelStatus.setText(""); + labelInfo.registerGraphicComponent(containerName,"labelInfo"); labelInfo.init(30, networkHeadPos+30); labelInfo.setText(""); labelInfo.setFont(CoreData::getInstance().getMenuFontBig()); //create + buttonDisconnect.registerGraphicComponent(containerName,"buttonDisconnect"); buttonDisconnect.init(450, 180, 125); + + buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow"); buttonPlayNow.init(525, 180, 125); xoffset=170; // fog - o - war // @350 ? 300 ? + + labelFogOfWar.registerGraphicComponent(containerName,"labelFogOfWar"); labelFogOfWar.init(xoffset+150, aHeadPos, 80); labelFogOfWar.setText(lang.get("FogOfWar")); + + listBoxFogOfWar.registerGraphicComponent(containerName,"listBoxFogOfWar"); listBoxFogOfWar.init(xoffset+150, aPos, 80); listBoxFogOfWar.pushBackItem(lang.get("Yes")); listBoxFogOfWar.pushBackItem(lang.get("No")); @@ -110,8 +121,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxFogOfWar.setEditable(false); + labelAllowObservers.registerGraphicComponent(containerName,"labelAllowObservers"); labelAllowObservers.init(xoffset+50, aHeadPos, 80); labelAllowObservers.setText(lang.get("AllowObservers")); + + listBoxAllowObservers.registerGraphicComponent(containerName,"listBoxAllowObservers"); listBoxAllowObservers.init(xoffset+50, aPos, 80); listBoxAllowObservers.pushBackItem(lang.get("No")); listBoxAllowObservers.pushBackItem(lang.get("Yes")); @@ -120,7 +134,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM // Enable Observer Mode + labelEnableObserverMode.registerGraphicComponent(containerName,"labelEnableObserverMode"); labelEnableObserverMode.init(xoffset+250, aHeadPos, 80); + + listBoxEnableObserverMode.registerGraphicComponent(containerName,"listBoxEnableObserverMode"); listBoxEnableObserverMode.init(xoffset+250, aPos, 110); listBoxEnableObserverMode.pushBackItem(lang.get("Yes")); listBoxEnableObserverMode.pushBackItem(lang.get("No")); @@ -128,8 +145,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxEnableObserverMode.setEditable(false); labelEnableObserverMode.setText(lang.get("EnableObserverMode")); + labelPathFinderType.registerGraphicComponent(containerName,"labelPathFinderType"); labelPathFinderType.init(xoffset+450, aHeadPos, 80); labelPathFinderType.setText(lang.get("PathFinderType")); + + listBoxPathFinderType.registerGraphicComponent(containerName,"listBoxPathFinderType"); listBoxPathFinderType.init(xoffset+450, aPos, 150); listBoxPathFinderType.pushBackItem(lang.get("PathFinderTypeRegular")); listBoxPathFinderType.pushBackItem(lang.get("PathFinderTypeRoutePlanner")); @@ -138,8 +158,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM // Network Frame Period xoffset=0; + labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod"); labelNetworkFramePeriod.init(xoffset+170, networkHeadPos, 80); labelNetworkFramePeriod.setText(lang.get("NetworkFramePeriod")); + + listBoxNetworkFramePeriod.registerGraphicComponent(containerName,"listBoxNetworkFramePeriod"); listBoxNetworkFramePeriod.init(xoffset+170, networkPos, 80); listBoxNetworkFramePeriod.pushBackItem("10"); listBoxNetworkFramePeriod.pushBackItem("20"); @@ -149,8 +172,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxNetworkFramePeriod.setEditable(false); // Network Frame Period + labelNetworkPauseGameForLaggedClients.registerGraphicComponent(containerName,"labelNetworkPauseGameForLaggedClients"); labelNetworkPauseGameForLaggedClients.init(xoffset+420, networkHeadPos, 80); labelNetworkPauseGameForLaggedClients.setText(lang.get("NetworkPauseGameForLaggedClients")); + + listBoxNetworkPauseGameForLaggedClients.registerGraphicComponent(containerName,"listBoxNetworkPauseGameForLaggedClients"); listBoxNetworkPauseGameForLaggedClients.init(xoffset+420, networkPos, 80); listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("No")); listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes")); @@ -159,8 +185,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM // Enable Server Controlled AI + labelEnableServerControlledAI.registerGraphicComponent(containerName,"labelEnableServerControlledAI"); labelEnableServerControlledAI.init(xoffset+640, networkHeadPos, 80); labelEnableServerControlledAI.setText(lang.get("EnableServerControlledAI")); + + listBoxEnableServerControlledAI.registerGraphicComponent(containerName,"listBoxEnableServerControlledAI"); listBoxEnableServerControlledAI.init(xoffset+640, networkPos, 80); listBoxEnableServerControlledAI.pushBackItem(lang.get("Yes")); listBoxEnableServerControlledAI.pushBackItem(lang.get("No")); @@ -171,17 +200,23 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM //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) + listBoxMap.registerGraphicComponent(containerName,"listBoxMap"); listBoxMap.init(xoffset+100, mapPos, 200); listBoxMap.setEditable(false); + + labelMap.registerGraphicComponent(containerName,"labelMap"); labelMap.init(xoffset+100, mapHeadPos); labelMap.setText(lang.get("Map")); //tileset listBox //listBoxTileset.init(500, 260, 150); + listBoxTileset.registerGraphicComponent(containerName,"listBoxTileset"); listBoxTileset.init(xoffset+350, mapPos, 150); listBoxTileset.setEditable(false); //listBoxTileset.setItems(results); //labelTileset.init(500, 290); + + labelTileset.registerGraphicComponent(containerName,"labelTileset"); labelTileset.init(xoffset+350, mapHeadPos); labelTileset.setText(lang.get("Tileset")); @@ -191,7 +226,11 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxTechTree.setEditable(false); //listBoxTechTree.setItems(results); //labelTechTree.init(700, 290); + + listBoxTechTree.registerGraphicComponent(containerName,"listBoxTechTree"); listBoxTechTree.init(xoffset+550, mapPos, 150); + + labelTechTree.registerGraphicComponent(containerName,"labelTechTree"); labelTechTree.init(xoffset+550, mapHeadPos); labelTechTree.setText(lang.get("TechTree")); @@ -201,27 +240,42 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM xoffset=120; int rowHeight=27; for(int i=0; i"); } + labelControl.registerGraphicComponent(containerName,"labelControl"); labelControl.init(xoffset+200, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); labelControl.setText(lang.get("Control")); + labelFaction.registerGraphicComponent(containerName,"labelFaction"); labelFaction.init(xoffset+350, setupPos, GraphicListBox::defW, GraphicListBox::defH, true); labelFaction.setText(lang.get("Faction")); + labelTeam.registerGraphicComponent(containerName,"labelTeam"); labelTeam.init(xoffset+520, setupPos, 60, GraphicListBox::defH, true); labelTeam.setText(lang.get("Team")); @@ -266,6 +320,9 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM listBoxControls[0].setSelectedItemIndex(ctHuman); chatManager.init(&console, -1,true); + + GraphicComponent::applyAllCustomProperties(containerName); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } MenuStateConnectedGame::~MenuStateConnectedGame() { diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index ac2072c4..78cb5195 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -30,8 +30,9 @@ enum JoinMenu{ // class MenuStateConnectedGame // =============================== -class MenuStateConnectedGame: public MenuState{ +class MenuStateConnectedGame: public MenuState { private: + static const char *containerName; GraphicButton buttonDisconnect; GraphicButton buttonPlayNow; GraphicLabel labelControl; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 06387998..5e03ace9 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -45,6 +45,8 @@ struct FormatString { // class MenuStateCustomGame // ===================================================== +const char *MenuStateCustomGame::containerName = "CustomGame"; + MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver): MenuState(program, mainMenu, "new-game") { @@ -65,6 +67,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b showFullConsole=false; + mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox"); mainMessageBox.init(lang.get("Ok")); mainMessageBox.setEnabled(false); mainMessageBoxState=0; @@ -106,8 +109,13 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b vector teamItems, controlItems, results; //create + buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); buttonReturn.init(250, 180, 125); + + buttonRestoreLastSettings.registerGraphicComponent(containerName,"buttonRestoreLastSettings"); buttonRestoreLastSettings.init(250+130, 180, 200); + + buttonPlayNow.registerGraphicComponent(containerName,"buttonPlayNow"); buttonPlayNow.init(250+130+205, 180, 125); int labelOffset=23; @@ -148,6 +156,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b formattedPlayerSortedMaps[mapInfo.players].push_back(formatString(mapFiles.at(i))); } + labelLocalIP.registerGraphicComponent(containerName,"labelLocalIP"); labelLocalIP.init(410, networkHeadPos+labelOffset); string ipText = "none"; @@ -166,15 +175,23 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b // Map xoffset=70; + labelMap.registerGraphicComponent(containerName,"labelMap"); labelMap.init(xoffset+100, mapHeadPos); labelMap.setText(lang.get("Map")+":"); + + listBoxMap.registerGraphicComponent(containerName,"listBoxMap"); listBoxMap.init(xoffset+100, mapPos, 200); listBoxMap.setItems(formattedPlayerSortedMaps[0]); + + labelMapInfo.registerGraphicComponent(containerName,"labelMapInfo"); labelMapInfo.init(xoffset+100, mapPos-labelOffset, 200, 40); // MapFilter + labelMapFilter.registerGraphicComponent(containerName,"labelMapFilter"); labelMapFilter.init(xoffset+310, mapHeadPos); labelMapFilter.setText(lang.get("MapFilter")+":"); + + listBoxMapFilter.registerGraphicComponent(containerName,"listBoxMapFilter"); listBoxMapFilter.init(xoffset+310, mapPos, 80); listBoxMapFilter.pushBackItem("-"); for(int i=1; i externalPortList; @@ -281,8 +327,11 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b //listBoxPublishServer.setSelectedItemIndex(0); // Network Frame Period + labelNetworkFramePeriod.registerGraphicComponent(containerName,"labelNetworkFramePeriod"); labelNetworkFramePeriod.init(xoffset+350, networkHeadPos, 80); labelNetworkFramePeriod.setText(lang.get("NetworkFramePeriod")); + + listBoxNetworkFramePeriod.registerGraphicComponent(containerName,"listBoxNetworkFramePeriod"); listBoxNetworkFramePeriod.init(xoffset+350, networkPos, 80); listBoxNetworkFramePeriod.pushBackItem("10"); listBoxNetworkFramePeriod.pushBackItem("20"); @@ -291,8 +340,11 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b listBoxNetworkFramePeriod.setSelectedItem("20"); // Network Frame Period + labelNetworkPauseGameForLaggedClients.registerGraphicComponent(containerName,"labelNetworkPauseGameForLaggedClients"); labelNetworkPauseGameForLaggedClients.init(xoffset+520, networkHeadPos, 80); labelNetworkPauseGameForLaggedClients.setText(lang.get("NetworkPauseGameForLaggedClients")); + + listBoxNetworkPauseGameForLaggedClients.registerGraphicComponent(containerName,"listBoxNetworkPauseGameForLaggedClients"); listBoxNetworkPauseGameForLaggedClients.init(xoffset+520, networkPos, 80); listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("No")); listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes")); @@ -300,8 +352,11 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b // Enable Server Controlled AI + labelEnableServerControlledAI.registerGraphicComponent(containerName,"labelEnableServerControlledAI"); labelEnableServerControlledAI.init(xoffset+670, networkHeadPos, 80); labelEnableServerControlledAI.setText(lang.get("EnableServerControlledAI")); + + listBoxEnableServerControlledAI.registerGraphicComponent(containerName,"listBoxEnableServerControlledAI"); listBoxEnableServerControlledAI.init(xoffset+670, networkPos, 80); listBoxEnableServerControlledAI.pushBackItem(lang.get("Yes")); listBoxEnableServerControlledAI.pushBackItem(lang.get("No")); @@ -311,20 +366,34 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b xoffset=120; int rowHeight=27; for(int i=0; isetUniqueID(__FILE__); publishToMasterserverThread->start(); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index d0e2d6c9..49e4e56f 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -24,6 +24,9 @@ namespace Glest{ namespace Game{ class MenuStateCustomGame : public MenuState, public SimpleTaskCallbackInterface { private: + + static const char *containerName; + GraphicButton buttonReturn; GraphicButton buttonPlayNow; GraphicButton buttonRestoreLastSettings;