From 198d2aeb9833af0f01584d8cc4cdbd3bcb10611f Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Fri, 2 Apr 2010 14:21:43 +0000 Subject: [PATCH] improved resolution change in options menu --- source/glest_game/menu/menu_state_options.cpp | 63 ++++++++++++++++++- source/glest_game/menu/menu_state_options.h | 4 ++ .../sources/platform/sdl/platform_util.cpp | 21 ++++--- 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index f15e02f72..6c4b92b27 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -46,7 +46,9 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): int buttonRowPos=80; int captionOffset=75; - + mainMessageBox.init(lang.get("Ok")); + mainMessageBox.setEnabled(false); + mainMessageBoxState=0; labelAudioSection.init(leftLabelStart+captionOffset, leftline); labelAudioSection.setFont(CoreData::getInstance().getMenuFontVeryBig()); @@ -119,7 +121,8 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): for(list::const_iterator it= modeInfos.begin(); it!=modeInfos.end(); ++it){ listBoxScreenModes.pushBackItem((*it).getString()); } - listBoxScreenModes.setSelectedItem(config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight")); + listBoxScreenModes.setSelectedItem(config.getString("ScreenWidth")+"x"+ + config.getString("ScreenHeight")+"-"+intToStr(config.getInt("ColorBits"))); leftline-=30; //filter @@ -180,14 +183,58 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): } +void MenuStateOptions::showMessageBox(const string &text, const string &header, bool toggle){ + if(!toggle){ + mainMessageBox.setEnabled(false); + } + + if(!mainMessageBox.getEnabled()){ + mainMessageBox.setText(text); + mainMessageBox.setHeader(header); + mainMessageBox.setEnabled(true); + } + else{ + mainMessageBox.setEnabled(false); + } +} + + + void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){ Config &config= Config::getInstance(); CoreData &coreData= CoreData::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance(); - if(buttonOk.mouseClick(x, y)){ + if(mainMessageBox.getEnabled()){ + int button= 1; + if(mainMessageBox.mouseClick(x, y, button)) + { + soundRenderer.playFx(coreData.getClickSoundA()); + if(button==1) + { + if(mainMessageBoxState==1) + { + mainMessageBox.setEnabled(false); + saveConfig(); + mainMenu->setState(new MenuStateRoot(program, mainMenu)); + } + else + mainMessageBox.setEnabled(false); + } + } + } + else if(buttonOk.mouseClick(x, y)){ soundRenderer.playFx(coreData.getClickSoundA()); + + string currentResolution=config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight")+"-"+intToStr(config.getInt("ColorBits")); + string selectedResolution=listBoxScreenModes.getSelectedItem(); + if(currentResolution!=selectedResolution){ + mainMessageBoxState=1; + Lang &lang= Lang::getInstance(); + showMessageBox(lang.get("RestartNeeded"), lang.get("ResolutionChanged"), false); + return; + } saveConfig(); mainMenu->setState(new MenuStateRoot(program, mainMenu)); } @@ -220,6 +267,9 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){ } void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){ + if (mainMessageBox.getEnabled()) { + mainMessageBox.mouseMove(x, y); + } buttonOk.mouseMove(x, y); buttonAbort.mouseMove(x, y); buttonAutoConfig.mouseMove(x, y); @@ -269,6 +319,11 @@ void MenuStateOptions::keyPress(char c){ void MenuStateOptions::render(){ Renderer &renderer= Renderer::getInstance(); + if(mainMessageBox.getEnabled()){ + renderer.renderMessageBox(&mainMessageBox); + } + else + { renderer.renderButton(&buttonOk); renderer.renderButton(&buttonAbort); renderer.renderButton(&buttonAutoConfig); @@ -297,6 +352,7 @@ void MenuStateOptions::render(){ renderer.renderLabel(&labelMiscSection); renderer.renderLabel(&labelScreenModes); renderer.renderListBox(&listBoxScreenModes); + } } void MenuStateOptions::saveConfig(){ @@ -333,6 +389,7 @@ void MenuStateOptions::saveConfig(){ { config.setInt("ScreenWidth",(*it).width); config.setInt("ScreenHeight",(*it).height); + config.setInt("ColorBits",(*it).depth); } } } diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index d4bc2cb73..f51ec8861 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -56,6 +56,9 @@ private: GraphicLabel labelAudioSection; GraphicLabel labelMiscSection; + GraphicMessageBox mainMessageBox; + int mainMessageBoxState; + public: MenuStateOptions(Program *program, MainMenu *mainMenu); @@ -70,6 +73,7 @@ public: private: void saveConfig(); void setActiveInputLable(GraphicLabel* newLable); + void showMessageBox(const string &text, const string &header, bool toggle); }; }}//end namespace diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index 6fca10b98..de6323b4c 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -576,7 +576,7 @@ void getFullscreenVideoModes(list *modeinfos) { uniqueResList[lookupKey] = true; modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel)); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d - %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel); } /* Check if our resolution is restricted */ else if (modes == (SDL_Rect**)-1) { @@ -588,7 +588,7 @@ void getFullscreenVideoModes(list *modeinfos) { uniqueResList[lookupKey] = true; modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel)); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d - %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel); } else{ /* Print valid modes */ @@ -597,12 +597,19 @@ void getFullscreenVideoModes(list *modeinfos) { int bestW = -1; int bestH = -1; for(int i=0; modes[i]; ++i) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h,modes[i]->x); - string lookupKey = intToStr(modes[i]->w) + "_" + intToStr(modes[i]->h) + "_" + intToStr(modes[i]->x); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h,bpp); + string lookupKey = intToStr(modes[i]->w) + "_" + intToStr(modes[i]->h) + "_" + intToStr(bpp); if(uniqueResList.find(lookupKey) == uniqueResList.end()) { uniqueResList[lookupKey] = true; - modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,modes[i]->x)); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h); + modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,bpp)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d - %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h,bpp); + } + // fake the missing 16 bit resolutions in linux + string lookupKey16 = intToStr(modes[i]->w) + "_" + intToStr(modes[i]->h) + "_" + intToStr(16); + if(uniqueResList.find(lookupKey16) == uniqueResList.end()) { + uniqueResList[lookupKey16] = true; + modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,16)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d - %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h,16); } } } @@ -706,7 +713,7 @@ ModeInfo::ModeInfo(int w, int h, int d) { } string ModeInfo::getString() const{ - return intToStr(width)+"x"+intToStr(height); + return intToStr(width)+"x"+intToStr(height)+"-"+intToStr(depth); } }}//end namespace