- allow changing screen resolution and fullscreen mode in options menu with confirmation

This commit is contained in:
Mark Vejvoda 2013-01-01 10:18:42 +00:00
parent f8ef92213d
commit 46869536bb
4 changed files with 145 additions and 31 deletions

View File

@ -27,19 +27,29 @@ Metrics::Metrics() {
reloadData();
}
void Metrics::reload() {
void Metrics::reload(int resWidth, int resHeight) {
Metrics *metrics = getInstancePtr();
metrics->reloadData();
metrics->reloadData(resWidth, resHeight);
}
void Metrics::reloadData() {
void Metrics::reloadData(int resWidth, int resHeight) {
Config &config = Config::getInstance();
virtualW= 1000;
virtualH= 750;
screenW= config.getInt("ScreenWidth");
screenH= config.getInt("ScreenHeight");
if(resWidth > 0) {
screenW= resWidth;
}
else {
screenW= config.getInt("ScreenWidth");
}
if(resHeight > 0) {
screenH= resHeight;
}
else {
screenH= config.getInt("ScreenHeight");
}
minimapX= 10;
minimapY= 750-128-30+16;

View File

@ -44,7 +44,7 @@ private:
private:
Metrics();
static Metrics *getInstancePtr();
void reloadData();
void reloadData(int resWidth=-1, int resHeight=-1);
public:
static const Metrics &getInstance();
@ -69,7 +69,7 @@ public:
bool isInDisplay(int x, int y) const;
bool isInMinimap(int x, int y) const;
static void reload();
static void reload(int resWidth=-1, int resHeight=-1);
};
}}//end namespace

View File

@ -864,14 +864,55 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
int button= 0;
if(mainMessageBox.mouseClick(x, y, button)) {
soundRenderer.playFx(coreData.getClickSoundA());
if(button==0) {
if(mainMessageBoxState==1) {
if(button == 0) {
if(mainMessageBoxState == 1) {
mainMessageBoxState=0;
mainMessageBox.setEnabled(false);
saveConfig();
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"));
mainMenu->setState(new MenuStateRoot(program, mainMenu));
}
else {
mainMessageBox.setEnabled(false);
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"));
}
}
else {
if(mainMessageBoxState == 1) {
mainMessageBoxState=0;
mainMessageBox.setEnabled(false);
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"));
//!!!
// Revert resolution or fullscreen
checkBoxFullscreenWindowed.setValue(config.getBool("Windowed"));
string currentResString = config.getString("ScreenWidth") + "x" +
config.getString("ScreenHeight") + "-" +
intToStr(config.getInt("ColorBits"));
listBoxScreenModes.setSelectedItem(currentResString);
changeVideoModeFullScreen(!config.getBool("Windowed"));
WindowGl *window = this->program->getWindow();
window->ChangeVideoMode(true,
config.getInt("ScreenWidth"),
config.getInt("ScreenHeight"),
!config.getBool("Windowed"),
config.getInt("ColorBits"),
config.getInt("DepthBits"),
config.getInt("StencilBits"),
config.getBool("HardwareAcceleration","false"),
config.getBool("FullScreenAntiAliasing","false"),
config.getFloat("GammaValue","0.0"));
Metrics::reload();
this->mainMenu->init();
}
}
}
@ -901,13 +942,62 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
else if(buttonOk.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundA());
bool selectedFullscreenWindowed = checkBoxFullscreenWindowed.getValue();
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();
// if(currentResolution != selectedResolution ||
// currentFullscreenWindowed != selectedFullscreenWindowed) {
//
// changeVideoModeFullScreen(!config.getBool("Windowed"));
// WindowGl *window = this->program->getWindow();
// window->ChangeVideoMode(true,
// config.getInt("ScreenWidth"),
// config.getInt("ScreenHeight"),
// !config.getBool("Windowed"),
// config.getInt("ColorBits"),
// config.getInt("DepthBits"),
// config.getInt("StencilBits"),
// config.getBool("HardwareAcceleration","false"),
// config.getBool("FullScreenAntiAliasing","false"),
// config.getFloat("GammaValue","0.0"));
//
// Metrics::reload();
// this->mainMenu->init();
// }
changeVideoModeFullScreen(!selectedFullscreenWindowed);
const ModeInfo *selectedMode = NULL;
for(vector<ModeInfo>::const_iterator it= modeInfos.begin(); it!=modeInfos.end(); ++it) {
if((*it).getString() == selectedResolution) {
//config.setInt("ScreenWidth",(*it).width);
//config.setInt("ScreenHeight",(*it).height);
//config.setInt("ColorBits",(*it).depth);
selectedMode = &(*it);
}
}
WindowGl *window = this->program->getWindow();
window->ChangeVideoMode(true,
selectedMode->width,
selectedMode->height,
!selectedFullscreenWindowed,
selectedMode->depth,
config.getInt("DepthBits"),
config.getInt("StencilBits"),
config.getBool("HardwareAcceleration","false"),
config.getBool("FullScreenAntiAliasing","false"),
strToFloat(listBoxGammaCorrection.getSelectedItem()));
Metrics::reload(selectedMode->width,selectedMode->height);
this->mainMenu->init();
mainMessageBoxState=1;
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"),lang.get("Cancel"));
//showMessageBox(lang.get("RestartNeeded"), lang.get("ResolutionChanged"), false);
//return;
showMessageBox(lang.get("ResolutionChanged"), lang.get("Notice"), false);
return;
}
string currentFontSizeAdjustment=config.getString("FontSizeAdjustment");
string selectedFontSizeAdjustment=listFontSizeAdjustment.getSelectedItem();
@ -919,38 +1009,50 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
}
bool currentFullscreenWindowed=config.getBool("Windowed");
bool selectedFullscreenWindowed = checkBoxFullscreenWindowed.getValue();
//bool selectedFullscreenWindowed = checkBoxFullscreenWindowed.getValue();
if(currentFullscreenWindowed != selectedFullscreenWindowed) {
//mainMessageBoxState=1;
//Lang &lang= Lang::getInstance();
//showMessageBox(lang.get("RestartNeeded"), lang.get("DisplaySettingsChanged"), false);
//return;
}
saveConfig();
changeVideoModeFullScreen(!selectedFullscreenWindowed);
const ModeInfo *selectedMode = NULL;
for(vector<ModeInfo>::const_iterator it= modeInfos.begin(); it!=modeInfos.end(); ++it) {
if((*it).getString() == selectedResolution) {
//config.setInt("ScreenWidth",(*it).width);
//config.setInt("ScreenHeight",(*it).height);
//config.setInt("ColorBits",(*it).depth);
selectedMode = &(*it);
}
}
if(currentResolution != selectedResolution ||
currentFullscreenWindowed != selectedFullscreenWindowed) {
changeVideoModeFullScreen(!config.getBool("Windowed"));
WindowGl *window = this->program->getWindow();
window->ChangeVideoMode(true,
config.getInt("ScreenWidth"),
config.getInt("ScreenHeight"),
!config.getBool("Windowed"),
config.getInt("ColorBits"),
config.getInt("DepthBits"),
config.getInt("StencilBits"),
config.getBool("HardwareAcceleration","false"),
config.getBool("FullScreenAntiAliasing","false"),
config.getFloat("GammaValue","0.0"));
selectedMode->width,
selectedMode->height,
!selectedFullscreenWindowed,
selectedMode->depth,
config.getInt("DepthBits"),
config.getInt("StencilBits"),
config.getBool("HardwareAcceleration","false"),
config.getBool("FullScreenAntiAliasing","false"),
strToFloat(listBoxGammaCorrection.getSelectedItem()));
Metrics::reload();
Metrics::reload(selectedMode->width,selectedMode->height);
this->mainMenu->init();
mainMessageBoxState=1;
Lang &lang= Lang::getInstance();
mainMessageBox.init(lang.get("Ok"),lang.get("Cancel"));
//showMessageBox(lang.get("RestartNeeded"), lang.get("ResolutionChanged"), false);
showMessageBox(lang.get("DisplaySettingsChanged"), lang.get("Notice"), false);
return;
}
mainMenu->setState(new MenuStateRoot(program, mainMenu));
return;
//saveConfig();
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
//return;
}
else if(buttonAbort.mouseClick(x, y)){
soundRenderer.playFx(coreData.getClickSoundA());

View File

@ -62,6 +62,8 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//printf("In [%s::%s %d] PlatformCommon::Private::shouldBeFullscreen = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,PlatformCommon::Private::shouldBeFullscreen);
int flags = SDL_OPENGL;
if(PlatformCommon::Private::shouldBeFullscreen) {
flags |= SDL_FULLSCREEN;