diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 10eaf4e5..806746ba 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -708,6 +708,281 @@ bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { return false; } +// ===================================================== +// class GraphicComboBox +// ===================================================== + +const int GraphicComboBox::defH= 22; +const int GraphicComboBox::defW= 140; + +GraphicComboBox::GraphicComboBox(const std::string &containerName, const std::string &objName) +: GraphicComponent(containerName, objName), dropDownButton(containerName, objName + "_button") { + selectedItemIndex = 0; + lighted = false; +} + +void GraphicComboBox::init(int x, int y, int w, int h, Vec3f textColor){ + GraphicComponent::init(x, y, w, h); + + this->textColor=textColor; + dropDownButton.init(x+w-h, y, h, h); + dropDownButton.setText("v"); + + popupLineCount=15; + popupButtonHeight=20; + + int scrollBarLength=popupLineCount*popupButtonHeight; + int popupYpos=y+h; + if( y>200) popupYpos=y-scrollBarLength; + scrollBar.init(x+w-h,popupYpos,false,scrollBarLength,20); + scrollBar.setVisibleSize(popupLineCount); + scrollBar.setVisibleStart(0); + scrollBar.setLighted(false); + scrollBar.setVisible(true); + + selectedItemIndex=-1; + popupShowing=false; + lighted=false; + preselectedItemIndex=-1; + +} + +const string & GraphicComboBox::getTextNativeTranslation(int index) { + if(this->translated_items.empty() == true || + index < 0 || + index >= (int)this->translated_items.size() || + this->items.size() != this->translated_items.size()) { + return this->text; + } + else { + return this->translated_items[index]; + } +} + +const string & GraphicComboBox::getTextNativeTranslation() { + return getTextNativeTranslation(this->selectedItemIndex); +} + +//queryes +void GraphicComboBox::pushBackItem(string item, string translated_item){ + items.push_back(item); + translated_items.push_back(translated_item); + setSelectedItemIndex(0); + createButton(item); +} + +void GraphicComboBox::clearItems(){ + clearButtons(); + items.clear(); + translated_items.clear(); + selectedItemIndex=-1; + setText(""); +} + +GraphicButton* GraphicComboBox::createButton(string item) { + GraphicButton *button = new GraphicButton(); + button->init(getX(), scrollBar.getY(), getW()-scrollBar.getW(), getPopupButtonHeight()); + button->setText(item); + button->setUseCustomTexture(true); + button->setCustomTexture(CoreData::getInstance().getCustomTexture()); + popupButtons.push_back(button); + scrollBar.setElementCount((int)popupButtons.size()); + layoutButtons(); + return button; +} + +void GraphicComboBox::layoutButtons() { + if (scrollBar.getElementCount() != 0) { + int keyButtonsYBase=scrollBar.getY()+scrollBar.getLength();; + for (int i = scrollBar.getVisibleStart(); + i <= scrollBar.getVisibleEnd(); ++i) { + if(i >= (int)popupButtons.size()) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"i >= popupButtons.size(), i = %d, popupButtons.size() = %d",i,(int)popupButtons.size()); + throw megaglest_runtime_error(szBuf); + } + popupButtons[i]->setY(keyButtonsYBase - getPopupButtonHeight() * (i+1 + - scrollBar.getVisibleStart())); + } + } + +} + +void GraphicComboBox::clearButtons() { + while(!popupButtons.empty()) { + delete popupButtons.back(); + popupButtons.pop_back(); + } + scrollBar.setElementCount(0); +} + +void GraphicComboBox::setItems(const vector &items, const vector translated_items){ + clearItems(); + this->items= items; + this->translated_items = translated_items; + if(items.empty() == false) { + setSelectedItemIndex(0); + } + else { + selectedItemIndex=-1; + setText(""); + } + for(int idx = 0; idx < (int)items.size(); idx++) { + createButton(this->items[idx]); + } +} + +void GraphicComboBox::setSelectedItemIndex(int index, bool errorOnMissing){ + if(errorOnMissing == true && (index < 0 || index >= (int)items.size())) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Index not found in listbox name: [%s] value index: %d size: %lu",this->instanceName.c_str(),index,(unsigned long)items.size()); + throw megaglest_runtime_error(szBuf); + } + selectedItemIndex= index; + preselectedItemIndex= index; + setText(getSelectedItem()); +} + + +void GraphicComboBox::setX(int x) { + this->x= x; + dropDownButton.setX(x+w); +} + +void GraphicComboBox::setY(int y) { + this->y= y; + dropDownButton.setY(y); +} + +void GraphicComboBox::setEditable(bool editable){ + dropDownButton.setEditable(editable); + GraphicComponent::setEditable(editable); +} + +bool GraphicComboBox::hasItem(string item) const { + bool result = false; + vector::const_iterator iter= find(items.begin(), items.end(), item); + if(iter != items.end()) { + result = true; + } + + return result; +} + +void GraphicComboBox::setSelectedItem(string item, bool errorOnMissing){ + vector::iterator iter; + + iter= find(items.begin(), items.end(), item); + + if(iter==items.end()) { + if(errorOnMissing == true) { + for(int idx = 0; idx < (int)items.size(); idx++) { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\ninstanceName [%s] idx = %d items[idx] = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,instanceName.c_str(),idx,items[idx].c_str()); + } + + char szBuf[8096]=""; + snprintf(szBuf,8096,"Value not found in listbox name: [%s] value: %s",this->instanceName.c_str(),item.c_str()); + throw megaglest_runtime_error(szBuf); + } + } + else { + setSelectedItemIndex(iter-items.begin()); + } + +} + +void GraphicComboBox::togglePopupVisibility(){ + if( popupShowing == true ){ + popupShowing=false; + scrollBar.setVisible(false); + } + else { + popupShowing=true; + scrollBar.setVisible(true); + layoutButtons(); + } +} + +bool GraphicComboBox::mouseMove(int x, int y){ + if(this->getVisible() == false) { + return false; + } + bool result=false; + result=result||scrollBar.mouseMove(x,y); + result=result||dropDownButton.mouseMove(x, y); + if (popupShowing) { + bool foundMouseOver=false; + for (int i = scrollBar.getVisibleStart(); i <= scrollBar.getVisibleEnd(); ++i) { + if (popupButtons[i]->mouseMove(x, y)) { + foundMouseOver=true; + result = true; + setPreselectedItemIndex(i); + layoutButtons(); + } + if(!foundMouseOver){ + setPreselectedItemIndex(getSelectedItemIndex()); + } + } + } + return result; +} + +bool GraphicComboBox::mouseClick(int x, int y) { + if(this->getVisible() == false) { + return false; + } + + if(!items.empty()) { + bool returnValue=true; + if( dropDownButton.mouseClick(x, y)&& selectedItemIndex>=0) { + scrollBar.setVisibleStart(selectedItemIndex); + popupButtons[selectedItemIndex]->setLighted(true); + togglePopupVisibility(); + } + else if(scrollBar.mouseClick(x,y)){ + layoutButtons(); + returnValue=false; + } + else if (popupShowing){ + returnValue=false; + for (int i = scrollBar.getVisibleStart(); + i <= scrollBar.getVisibleEnd(); ++i) { + if( popupButtons[i]->mouseClick(x,y)){ + setSelectedItemIndex(i); + layoutButtons(); + togglePopupVisibility(); + returnValue=true; + } + } + if(returnValue==false){ + returnValue=true; + togglePopupVisibility(); + setPreselectedItemIndex(selectedItemIndex); + } + } + else{ + returnValue=false; + } + + return returnValue; + } + return false; +} + +bool GraphicComboBox::mouseDown(int x, int y) { + if( scrollBar.mouseDown(x,y)){ + layoutButtons(); + return true; + } + return false; +} +void GraphicComboBox::mouseUp(int x, int y) { + scrollBar.mouseUp(x,y); +} + + + + // ===================================================== // class GraphicMessageBox // ===================================================== @@ -930,6 +1205,7 @@ void GraphicScrollBar::init(int x, int y, bool horizontal,int length, int thickn } bool GraphicScrollBar::mouseDown(int x, int y) { + bool result=false; if(getVisible() && getEnabled() && getEditable()) { if(activated && elementCount>0) @@ -949,11 +1225,11 @@ bool GraphicScrollBar::mouseDown(int x, int y) { visibleStart=startPos/partSize; setVisibleStart(visibleStart); - + result=true; } } } - return false; + return result; } void GraphicScrollBar::mouseUp(int x, int y) { diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index b93fbd31..51357158 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -244,6 +244,59 @@ public: virtual bool mouseMove(int x, int y); }; +// =========================================================== +// class GraphicScrollBar +// =========================================================== + +class GraphicScrollBar: public GraphicComponent { +public: + static const int defLength; + static const int defThickness; + +private: + bool activated; + bool lighted; + bool horizontal; + int elementCount; + int visibleSize; + int visibleStart; + + // position on component for renderer + int visibleCompPosStart; + int visibleCompPosEnd; + +public: + GraphicScrollBar(const std::string &containerName="", const std::string &objName=""); + void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness); + virtual bool mouseDown(int x, int y); + virtual bool mouseMove(int x, int y); + virtual void mouseUp(int x, int y); + virtual bool mouseClick(int x, int y); + + + bool getHorizontal() const {return horizontal;} + int getLength() const; + void setLength(int length) {horizontal?setW(length):setH(length);} + //int getThickness() const; + + + bool getLighted() const {return lighted;} + void setLighted(bool lighted) {this->lighted= lighted;} + + int getElementCount() const {return elementCount;} + void setElementCount(int elementCount); + int getVisibleSize() const {return visibleSize;} + void setVisibleSize(int visibleSize); + int getVisibleStart() const {return visibleStart;} + int getVisibleEnd() const {return visibleStart+visibleSize>elementCount-1?elementCount-1: visibleStart+visibleSize-1;} + void setVisibleStart(int visibleStart); + + int getVisibleCompPosStart() const {return visibleCompPosStart;} + int getVisibleCompPosEnd() const {return visibleCompPosEnd;} + void arrangeComponents(vector &gcs); +}; + + // =========================================================== // class GraphicListBox // =========================================================== @@ -298,9 +351,99 @@ public: }; // =========================================================== -// class GraphicMessageBox +// class GraphicComboBox // =========================================================== typedef vector GraphicButtons; +class GraphicComboBox: public GraphicComponent { +public: + static const int defH; + static const int defW; + +private: + GraphicScrollBar scrollBar; + GraphicButtons popupButtons; + GraphicButton dropDownButton; + bool popupShowing; + int preselectedItemIndex; + int popupLineCount; + int popupButtonHeight; + vector items; + vector translated_items; + int selectedItemIndex; + bool lighted; + Vec3f textColor; + +public: + GraphicComboBox(const std::string &containerName="", const std::string &objName=""); + void init(int x, int y, int w=defW, int h=defH, Vec3f textColor=GraphicComponent::customTextColor); + + int getItemCount() const {return (int)items.size();} + string getItem(int index) const {return items[index];} + int getSelectedItemIndex() const {return selectedItemIndex;} + string getSelectedItem() const {return items[selectedItemIndex];} + GraphicButton *getButton() {return &dropDownButton;} + GraphicScrollBar *getScrollbar() {return &scrollBar;} + GraphicButtons *getPopupButtons() {return &popupButtons;} + bool getLighted() const {return lighted;} + void setLighted(bool lighted) {this->lighted= lighted;} + Vec3f getTextColor() const {return textColor;} + void setTextColor(Vec3f color) {this->textColor= color;} + bool isDropDownShowing() {return this->popupShowing; } + + void pushBackItem(string item, string translated_item=""); + void clearItems(); + + GraphicButton* createButton(string item); + void setItems(const vector &items, const vector translated_items=vector()); + void setSelectedItemIndex(int index, bool errorOnMissing=true); + void setSelectedItem(string item, bool errorOnMissing=true); + void setEditable(bool editable); + + bool hasItem(string item) const; + + virtual void setX(int x); + virtual void setY(int y); + + virtual bool mouseMove(int x, int y); + virtual bool mouseClick(int x, int y); + virtual bool mouseDown(int x, int y); + virtual void mouseUp(int x, int y); + + virtual const string &getTextNativeTranslation(); + + int getPopupLineCount() const {return popupLineCount;} + void setPopupLineCount(int popupLineCount) { + this->popupLineCount = popupLineCount; + scrollBar.setLength(popupLineCount * popupButtonHeight); + } + + int getPopupButtonHeight() const {return popupButtonHeight; } + void setPopupButtonHeight(int popupButtonHeight) { + this->popupButtonHeight = popupButtonHeight; + scrollBar.setLength(popupLineCount * popupButtonHeight); + } + + string getPreselectedItem() const { + return items[preselectedItemIndex]; + } + + int getPreselectedItemIndex() const { + return preselectedItemIndex; + } + +private: + void setPreselectedItemIndex(int index) { + this->preselectedItemIndex = index; + } + virtual const string &getTextNativeTranslation(int index); + virtual void togglePopupVisibility(); + void clearButtons(); + void layoutButtons(); +}; + +// =========================================================== +// class GraphicMessageBox +// =========================================================== class GraphicMessageBox: public GraphicComponent { public: static const int defH; @@ -382,57 +525,6 @@ public: virtual bool mouseClick(int x, int y); }; -// =========================================================== -// class GraphicScrollBar -// =========================================================== - -class GraphicScrollBar: public GraphicComponent { -public: - static const int defLength; - static const int defThickness; - -private: - bool activated; - bool lighted; - bool horizontal; - int elementCount; - int visibleSize; - int visibleStart; - - // position on component for renderer - int visibleCompPosStart; - int visibleCompPosEnd; - -public: - GraphicScrollBar(const std::string &containerName="", const std::string &objName=""); - void init(int x, int y, bool horizontal,int length=defLength, int thickness=defThickness); - virtual bool mouseDown(int x, int y); - virtual bool mouseMove(int x, int y); - virtual void mouseUp(int x, int y); - virtual bool mouseClick(int x, int y); - - - bool getHorizontal() const {return horizontal;} - int getLength() const; - void setLength(int length) {horizontal?setW(length):setH(length);} - //int getThickness() const; - - - bool getLighted() const {return lighted;} - void setLighted(bool lighted) {this->lighted= lighted;} - - int getElementCount() const {return elementCount;} - void setElementCount(int elementCount); - int getVisibleSize() const {return visibleSize;} - void setVisibleSize(int visibleSize); - int getVisibleStart() const {return visibleStart;} - int getVisibleEnd() const {return visibleStart+visibleSize>elementCount-1?elementCount-1: visibleStart+visibleSize-1;} - void setVisibleStart(int visibleStart); - - int getVisibleCompPosStart() const {return visibleCompPosStart;} - int getVisibleCompPosEnd() const {return visibleCompPosEnd;} - void arrangeComponents(vector &gcs); -}; // =========================================================== // class PopupMenu diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 07cf24d3..19fb2104 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -3664,6 +3664,11 @@ void Renderer::renderScrollBar(const GraphicScrollBar *sb) { glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); + Vec4f fontColor; + fontColor=Vec4f(1.f, 1.f, 1.f, GraphicComponent::getFade()); + Vec4f color= fontColor; + glColor4fv(color.ptr()); + glBindTexture(GL_TEXTURE_2D, static_cast(backTexture)->getHandle()); glBegin(GL_TRIANGLE_STRIP); @@ -3704,20 +3709,6 @@ void Renderer::renderScrollBar(const GraphicScrollBar *sb) { glBindTexture(GL_TEXTURE_2D, static_cast(selectTexture)->getHandle()); - //button - 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); @@ -3873,6 +3864,110 @@ void Renderer::renderListBox(GraphicListBox *listBox) { glPopAttrib(); } +void Renderer::renderComboBox(GraphicComboBox *comboBox) { + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + return; + } + + if(comboBox->getVisible() == false) { + return; + } + + int x= comboBox->getX(); + int y= comboBox->getY(); + int h= comboBox->getH(); + int w= comboBox->getW(); + if(h>0){ + //background + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT); + glEnable(GL_BLEND); + + glColor4f(0.0f, 0.0f, 0.0f, 0.6f*comboBox->getFade()) ; + + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y+h); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glEnd(); + glPopAttrib(); + } + + renderButton(comboBox->getButton()); + + if( comboBox->isDropDownShowing()){ + renderScrollBar(comboBox->getScrollbar()); + + if(comboBox->getPopupButtons()->size() != 0) { + for(int i = comboBox->getScrollbar()->getVisibleStart(); + i <= comboBox->getScrollbar()->getVisibleEnd(); ++i) { + renderButton((* comboBox->getPopupButtons())[i]); + } + } + } + + glPushAttrib(GL_ENABLE_BIT); + glEnable(GL_BLEND); + + GraphicLabel label("ComboBox_render_label","label",false); + //label.setInstanceName("ComboBox_render_label"); + + label.init(comboBox->getX(), comboBox->getY(), comboBox->getW(), comboBox->getH(), true,comboBox->getTextColor()); + label.setText(comboBox->getText()); + label.setTextNativeTranslation(comboBox->getTextNativeTranslation()); + label.setFont(comboBox->getFont()); + label.setFont3D(comboBox->getFont3D()); + renderLabel(&label); + + + //lighting + + bool renderLighted= (comboBox->getLighted()); + + + if(renderLighted) { + float anim= GraphicComponent::getAnim(); + if(anim>0.5f) anim= 1.f-anim; + + Vec3f color=comboBox->getTextColor(); + int x= comboBox->getX()+comboBox->getButton()->getW(); + int y= comboBox->getY(); + int h= comboBox->getH(); + int w= comboBox->getW()-comboBox->getButton()->getW(); + + 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::renderMessageBox(GraphicMessageBox *messageBox) { const int headerHeight=25; if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 3eea90fa..47260bf9 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -550,6 +550,7 @@ public: void renderLine(const GraphicLine *line); void renderScrollBar(const GraphicScrollBar *sb); void renderListBox(GraphicListBox *listBox); + void renderComboBox(GraphicComboBox *comboBox); void renderMessageBox(GraphicMessageBox *listBox); void renderPopupMenu(PopupMenu *menu); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 4f1975f6..cc4016ba 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -111,6 +111,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, needToPublishDelayed=false; mapPublishingDelayTimer=time(NULL); headlessHasConnectedPlayer=false; + currentMapFile=""; lastCheckedCRCTilesetName = ""; lastCheckedCRCTechtreeName = ""; @@ -314,7 +315,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, //Map Filter listBoxMapFilter.registerGraphicComponent(containerName,"listBoxMapFilter"); - listBoxMapFilter.init(xoffset+260, mapPos-labelOffset, 60); + listBoxMapFilter.init(xoffset+260, mapPos+labelOffset, 60); listBoxMapFilter.pushBackItem("-"); for(int i=1; igetMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); + MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); + + loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true,true); + labelMapInfo.setText(mapInfo.desc); + updateControlers(); + updateNetworkSlots(); + + if(checkBoxPublishServer.getValue() == true) { + needToRepublishToMasterserver = true; + } + + if(hasNetworkGameSettings() == true) { + //delay publishing for 5 seconds + needToPublishDelayed=true; + mapPublishingDelayTimer=time(NULL); + } + } + else if(listBoxMap.isDropDownShowing()){ + //do nothing + } else { string advanceToItemStartingWith = ""; if(::Shared::Platform::Window::isKeyStateModPressed(KMOD_SHIFT) == true) { @@ -1154,27 +1185,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { RestoreLastGameSettings(); } - else if(listBoxMap.mouseClick(x, y,advanceToItemStartingWith)){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str()); - MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); - MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); - - loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",false), &mapInfo, true); - labelMapInfo.setText(mapInfo.desc); - updateControlers(); - updateNetworkSlots(); - - if(checkBoxPublishServer.getValue() == true) { - needToRepublishToMasterserver = true; - } - - if(hasNetworkGameSettings() == true) { - //delay publishing for 5 seconds - needToPublishDelayed=true; - mapPublishingDelayTimer=time(NULL); - } - } else if (checkBoxAdvanced.getValue() == 1 && listBoxFogOfWar.mouseClick(x, y)) { MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexCLI((publishToClientsThread != NULL ? publishToClientsThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); @@ -1350,7 +1361,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str()); - loadMapInfo(Config::getMapPath(getCurrentMapFile()), &mapInfo, true); + loadMapInfo(Config::getMapPath(getCurrentMapFile()), &mapInfo, true,true); labelMapInfo.setText(mapInfo.desc); updateControlers(); updateNetworkSlots(); @@ -2010,6 +2021,16 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) { if (mainMessageBox.getEnabled()) { mainMessageBox.mouseMove(x, y); } + + if (ms->get(mbLeft)) { + listBoxMap.mouseDown(x, y); + } + if (listBoxMap.isDropDownShowing()) { + listBoxMap.mouseMove(x, y); + loadMapInfo(Config::getMapPath(getCurrentMapFile(), "", false), &mapInfo, true, false); + labelMapInfo.setText(mapInfo.desc); + } + buttonReturn.mouseMove(x, y); buttonPlayNow.mouseMove(x, y); buttonRestoreLastSettings.mouseMove(x, y); @@ -2023,7 +2044,6 @@ void MenuStateCustomGame::mouseMove(int x, int y, const MouseState *ms) { listBoxTeams[i].mouseMove(x, y); } - listBoxMap.mouseMove(x, y); if(checkBoxAdvanced.getValue() == 1) { listBoxFogOfWar.mouseMove(x, y); @@ -2276,7 +2296,7 @@ void MenuStateCustomGame::render() { renderer.renderLabel(&labelMapInfo); renderer.renderLabel(&labelAdvanced); - renderer.renderListBox(&listBoxMap); + renderer.renderComboBox(&listBoxMap); renderer.renderListBox(&listBoxTileset); renderer.renderListBox(&listBoxMapFilter); renderer.renderListBox(&listBoxTechTree); @@ -4067,7 +4087,7 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin mapFile = formatString(mapFile); listBoxMap.setSelectedItem(mapFile); - loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true); + loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true,true); labelMapInfo.setText(mapInfo.desc); } @@ -4279,29 +4299,31 @@ bool MenuStateCustomGame::hasNetworkGameSettings() { return hasNetworkSlot; } -void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview) { - try { +void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview, bool doPlayerSetup) { + + if(currentMapFile!=file) + try { Lang &lang= Lang::getInstance(); if(MapPreview::loadMapInfo(file, mapInfo, lang.getString("MaxPlayers"),lang.getString("Size"),true) == true) { - ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); - for(int i = 0; i < GameConstants::maxPlayers; ++i) { - if(serverInterface->getSlot(i,true) != NULL && - (listBoxControls[i].getSelectedItemIndex() == ctNetwork || - listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned)) { - if(serverInterface->getSlot(i,true)->isConnected() == true) { - if(i+1 > mapInfo->players && - listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { - listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + if (doPlayerSetup) { + ServerInterface* serverInterface = NetworkManager::getInstance().getServerInterface(); + for (int i = 0; i < GameConstants::maxPlayers; ++i) { + if (serverInterface->getSlot(i, true) != NULL + && (listBoxControls[i].getSelectedItemIndex() == ctNetwork || listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned)) { + if (serverInterface->getSlot(i, true)->isConnected() == true) { + if (i + 1 > mapInfo->players && listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + } } } - } - 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); + 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); + } } // Not painting properly so this is on hold @@ -4314,6 +4336,7 @@ void MenuStateCustomGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMa cleanupMapPreviewTexture(); } } + currentMapFile=file; } catch(exception &e) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] loading map [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what(),file.c_str()); @@ -4659,7 +4682,7 @@ void MenuStateCustomGame::switchToNextMapGroup(const int direction){ string MenuStateCustomGame::getCurrentMapFile(){ int i=listBoxMapFilter.getSelectedItemIndex(); - int mapIndex=listBoxMap.getSelectedItemIndex(); + int mapIndex=listBoxMap.getPreselectedItemIndex(); if(playerSortedMaps[i].empty() == false) { return playerSortedMaps[i].at(mapIndex); } @@ -4797,7 +4820,7 @@ void MenuStateCustomGame::processScenario() { setupMapList(scenarioInfo.name); listBoxMap.setSelectedItem(formatString(scenarioInfo.mapName)); - loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true); + loadMapInfo(Config::getMapPath(getCurrentMapFile(),scenarioDir,true), &mapInfo, true,true); labelMapInfo.setText(mapInfo.desc); //printf("scenarioInfo.name [%s] [%s]\n",scenarioInfo.name.c_str(),listBoxMap.getSelectedItem().c_str()); @@ -4926,7 +4949,7 @@ void MenuStateCustomGame::processScenario() { else { setupMapList(""); listBoxMap.setSelectedItem(formatString(formattedPlayerSortedMaps[0][0])); - loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",true), &mapInfo, true); + loadMapInfo(Config::getMapPath(getCurrentMapFile(),"",true), &mapInfo, true,true); labelMapInfo.setText(mapInfo.desc); int initialTechSelection=setupTechList("", false); @@ -5043,7 +5066,7 @@ int MenuStateCustomGame::setupMapList(string scenario) { // fill playerSortedMaps and formattedPlayerSortedMaps according to map player count for(int i= 0; i < (int)mapFiles.size(); i++){// fetch info and put map in right list - loadMapInfo(Config::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false); + loadMapInfo(Config::getMapPath(mapFiles.at(i), scenarioDir, false), &mapInfo, false,true); if(GameConstants::maxPlayers+1 <= mapInfo.players) { char szBuf[8096]=""; @@ -5063,7 +5086,7 @@ int MenuStateCustomGame::setupMapList(string scenario) { loadScenarioInfo(file, &scenarioInfo); //printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str()); - loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false); + loadMapInfo(Config::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false,true); //printf("#6.2\n"); listBoxMapFilter.setSelectedItem(intToStr(mapInfo.players)); listBoxMap.setItems(formattedPlayerSortedMaps[mapInfo.players]); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 052be486..19c86788 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -57,7 +57,7 @@ private: GraphicLabel labelMapInfo; GraphicLabel labelGameName; - GraphicListBox listBoxMap; + GraphicComboBox listBoxMap; GraphicListBox listBoxFogOfWar; GraphicListBox listBoxTechTree; GraphicListBox listBoxTileset; @@ -225,6 +225,8 @@ private: int lastGameSettingsreceivedCount; + string currentMapFile; + public: MenuStateCustomGame(Program *program, MainMenu *mainMenu , bool openNetworkSlots= false, ParentMenuState parentMenuState=pNewGame, @@ -234,6 +236,7 @@ public: void mouseClick(int x, int y, MouseButton mouseButton); void mouseMove(int x, int y, const MouseState *mouseState); + void mouseUp(int x, int y, const MouseButton mouseButton); void render(); void update(); @@ -259,7 +262,7 @@ private: void lastPlayerDisconnected(); bool hasNetworkGameSettings(); void loadGameSettings(GameSettings *gameSettings, bool forceCloseUnusedSlots=false); - void loadMapInfo(string file, MapInfo *mapInfo,bool loadMapPreview); + void loadMapInfo(string file, MapInfo *mapInfo,bool loadMapPreview, bool doPlayerSetup); void cleanupMapPreviewTexture(); void updateControlers();